【发布时间】:2014-05-15 01:27:42
【问题描述】:
我有两个列表:
mylist = ['total','age','gender','region','sex']
checklist = ['total','civic']
我必须使用一些我继承的代码,如下所示:
for item in mylist:
if item in checklist:
do something:
如何使用上面的代码告诉我'civic'不在我的列表中?。
这本来是理想的方法,但我不能使用它,不要问我为什么。
for item in checklist:
if item not in mylist:
print item
结果:
civic
【问题讨论】:
-
它适用于我的 Python 2.7。 “if item not in mylist”或“if not item in mylist”都有效
标签: python list for-loop notin