【发布时间】:2017-09-16 02:30:57
【问题描述】:
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 都为小写。
【问题讨论】:
-
运行此代码时会得到什么输出?我觉得很好。此外,如果
current_ids是一个集合,即current_ids = {'mason' , 'chase' , 'erin' , 'guillermo' , 'george'},效率会更高
标签: python python-3.x coding-style