您的位置:首页 > 编程语言 > Python开发

python中把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字。

2017-10-30 11:52 603 查看
def calculate(dealStr):
    chgStr = ''
    for index,currentCh
in enumerate(dealStr):
        if index ==
0:
            firstCh = dealStr[0]
            if ord(firstCh) >
90 :
                # 字母为小写字母转大写字母
                ch = ord(firstCh) - 32
                chgStr += chr(ch)
            else:
                chgStr += firstCh
        else:
            firstCh = dealStr[index]
            if ord(firstCh) <=
90 :
                # 字母为大写字母转小写字母
                ch = ord(firstCh) + 32
                chgStr += chr(ch)
            else:
                chgStr += firstCh

    return chgStr

l1 = ['ajdM', 'DjfDi',
'jfhHLLp', 'heIIIl']
l2 = list(map(calculate, l1))
print(l2)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python3 map
相关文章推荐