我有一个字符串列表的Python 2.7:找到列表项忽略大小写
["oranges", "POTATOES", "Pencils", "PAper"]
我想找到列表中是否包含paper
,忽略大小写;以便下面的代码段应打印found
。我的列表只包含由仅英文字母组成的简单字符串 - 大写和小写。
item = 'paper'
stuff = ["oranges", "POTATOES", "Pencils", "PAper"]
if item in stuff:
print "found"
else:
print "Not found"
#How do I get the method to print "found"?
澄清:
我的列表实际上是一个列表的列表,我的逻辑是使用下面的结构:
if not any (item in x for x in stuff):
print "Not found"
else:
print "found"
后,他贴在编辑的代码我忍不住票... – squiguy
谢谢你这么多为优雅的回应! – kasavbere