如果单词的大写和小写字母不同,我如何检查两个不同列表中的相同单词? 我写了这个:
current_users=["michael", "peta", "jennifer", "clark", "tony"]
new_users=["jeffry", "PETA", "shuff", "TOny", "guy"]
for new_user in new_users:
if new_user.lower() in current_users:
print("Sorry, the name "+new_user+" is already taken.")
else:
print("The name "+ new_user+ " is available.")
但只有当第一个列表是小写时它才有效。是否可以轻松修改此代码以忽略案例中的差异?
答案 0 :(得分:4)
答案 1 :(得分:1)
if any(new_user.lower() == user.lower() for user in current_users)