列表推导式法 | #禁止重复注册#
利用列表推导式法建立附表进行识别
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!')