我有2个清单。第一个是list_A = ['Sasi', 'Babu', 'kuttapppan', 'mathayi']
,第二个列表是list_B = ['Raman', 'Kesavan', 'sasi', 'unni', 'Kuttappan']
。
我想比较这两个列表,并确定第二个列表中重复的值,而不管它是以大写字母还是小写字母开头。我尝试了以下方法:
if not [name for name in list_A if name in list_B]:
print name
但是它没有按预期工作。
最佳答案
#Might be better if we are dealing with huge lists.
list_A = ['Sasi', 'Babu', 'kuttapppan', 'mathayi']
list_B = ['Raman', 'Kesavan', 'sasi', 'unni', 'Kuttappan'].
d = [x.lower() for x in list_A] # make dict of list with less elements
for m in list_B: # search against bigger list
if m.lower() in d: print(m)
关于python - 不区分大小写的两个列表的比较,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33643757/