题解 | #禁止重复注册#

禁止重复注册

https://www.nowcoder.com/practice/43acd439112c4b85a9168ad3dd7e2bd1

current_users = ['Niuniu', 'Niumei', 'GURR', 'LOLO']
# 将字符全部转为小写传入1中
current_users1 = list(map(lambda x: x.lower() , current_users))
new_users = ['GurR', 'Niu Ke Le', 'LoLo', 'Tuo Rui Chi']
# 将字符全部转为小写传入1中
new_users1 = list(map(lambda x: x.lower() , new_users))
# 遍历比较1中的小写
for i in new_users1:
    if i in current_users1:
		# 先用new_users1.index(i)获得i在1中的索引,再用这个索引去在原来的list里找到对应的名字
        print(f'The user name {new_users[new_users1.index(i)]} has already been registered! Please change it and try again!')
    else:
		# 先用new_users1.index(i)获得i在1中的索引,再用这个索引去在原来的list里找到对应的名字
        print(f'Congratulations, the user name {new_users[new_users1.index(i)]} is available!')

全部评论

相关推荐

青春运维少年不会梦到...:实习大王
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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