列表推导式法 | #禁止重复注册#

利用列表推导式法建立附表进行识别

current_users = ['Niuniu', 'Niumei', 'GURR', 'LOLO']
new_users = ['GurR', 'Niu Ke Le', 'LoLo', 'Tuo Rui Chi']

# 列表推导式思路——先将元素全部小写,再在最终结果返回对应下标位置元素
lowercase_cu = [item.lower() for item in current_users]
lowercase_nu = [item.lower() for item in new_users]

for i in range(len(lowercase_nu)):
    if lowercase_nu[i] in lowercase_cu:
        print(f'The user name {new_users[i]} has already been registered! Please change it and try again!')
    else:
        print(f'Congratulations, the user name {new_users[i]} is available!') 



全部评论

相关推荐

程序员小白条:你是沟通了900个,不是投了900份简历,你能投900份,意味着对面都要回复你900次,你早就找到实习了,没亮点就是这样的,别局限地区,时间投的也要早,现在都要7月了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务