current_ids = ['mason' , 'chase' , 'erin' , 'guillermo' , 'george']
new_ids = ['sara' , 'gregory' , 'ChaSe' , 'josh' , 'Erin']
for new in new_ids:
if new.lower() in current_ids:
print("This ID is already taken. Choose another one.")
else:
print("You aight man this ID is gucci")
我正在努力使循环检查新的ID是否已经被使用,如果它们是,那么它打印出ID已被使用。根据python,“Erin”和“erin”不一样。我想知道我需要添加什么才能使两个列表处于相同的情况。例如,curent_ids和new_ids都是小写的。
答案 0 :(得分:1)
您提供的示例似乎有效,但我会假设current_ids
可能混合使用大写/小写。
你可以做的是使用列表理解将current_ids中的每个字符串转换为小写:
current_ids = [i.lower() for i in current_ids]
这将创建current_ids
全部小写的每个单词的新列表。
然后,您可以像现在一样进行比较(if new.lower() in current_ids
)