How do I automatically capitalize a person's name?

90 Views Asked by At

How do I automatically capitalize a person's name?

Suppose that there is a cellphone app where people sign-up for volunteer work opportunities and/or paid jobs.

We wish to capitalize names of volunteers.

INPUT OUTPUT
Noodlum Leumas Noodlum Leumas
NoOdLuM LeUmAs Noodlum Leumas
noodlum leumas Noodlum Leumas
nOODLUM lEUMAS Noodlum Leumas

I have filed job applications with multiple multi-billion dollar corporations such that the corporation cellphone app displayed an error message complaining that I typed my name in all-caps or all-lower case letters.

In order to improve the end-user's experience (for better UX design) we can fix the capitalization on their name for them.

1

There are 1 best solutions below

1
Toothpick Anemone On

The following is a partial solution, but not the best answer.

Someone else is sure to post an even better answer and receive more upvotes.

For instance, McDonald and MkKormic are unlikely to be capitalized correctly.

INPUT CORRECT OUTPUT
mcdonald McDonald
MKCORMIC MkCormic
noodlum leumas Noodlum Leumas
nOODLUM lEUMAS Noodlum Leumas
def auto_captialize(istring:str) -> str:
    """
        input parameter namd `istring` is input string
    """
    # `sepwrds` is `seperated words`
    iwords = istring.split()
    
    owords = type(iwords)
    
    for iword in iwords:
        ileft_side  = iword[0]
        iright_side = iword[1:] 
        
        # convert left side of the word into all
        # uppercase letters
        oleft_side  = ileft_side.upper()
        
        oright_side = iright_side.lower()
        
        oword = oleft_side + oright_side
        
        # Append a string to the container of output words
        # insert instance of string class into somthing like List of strings
        owords.append(oword)
        
    ostring = " ".join(owords)
    # ostring ...... is ...... `output string`
    return ostring
    
    
######################################

inames = [
    "Noodlum Leumas",
    "NoOdLuM LeUmAs",
    "noodlum leumas",
    "nOODLUM lEUMAS",
]

for iname in inames:
   oname = auto_captialize(iname)
   print(oname)