如何自动将人名大写?

问题描述 投票:0回答:1

如何自动将人名大写?

假设有一个手机应用程序,人们可以在其中注册志愿者工作机会和/或有偿工作。

我们希望志愿者的名字大写。

输入 输出
Noodlum Leumas
Noodlum Leumas
NoOdLuM LeUmAs
Noodlum Leumas
noodlum leumas
Noodlum Leumas
nOODLUM lEUMAS
Noodlum Leumas

我向多家价值数十亿美元的公司提交了工作申请,该公司的手机应用程序显示一条错误消息,抱怨我以全大写或全小写字母输入了我的名字。

为了改善最终用户体验(更好的用户体验设计),我们可以修复他们名字的大写。

regex regular-language
1个回答
0
投票

以下是部分解决方案,但不是最佳答案。

其他人肯定会发布更好的答案并获得更多的赞成票。

例如,

McDonald
MkKormic
不太可能正确大写。

输入 正确的输出
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)
© www.soinside.com 2019 - 2024. All rights reserved.