Python用列表解析不区分元素大小写

遍历列表current——usrs,对于其中的每个用户名都检查是否被使用,且不区分大小写。

current_usrs = ['alice','Bob','carolina','admin','eve']
new_usrs = ['Alice','bob''sevischi','bruce','hellman']  

for usr in new_usrs:
      if usr.lower() in [current_usr.lower() for current_usr in current_usrs] :  
 #关键就是要学会使用列表解析

           print(usr + " was been used.")

明白了思想,程序都是简单的。

原文地址:https://www.cnblogs.com/hhjfighting/p/7684038.html