我有一个元组列表Python http://en.wikipedia.org/wiki/Python_%28programming_language%29,并且我有一个条件,仅当元组不在列表中时我才想采用分支(如果它在列表中,那么我不想采用 if 分支)
if curr_x -1 > 0 and (curr_x-1 , curr_y) not in myList:
# Do Something
但这对我来说并没有真正起作用。我做错了什么?
该错误可能位于代码中的其他位置,因为它应该可以正常工作:
>>> 3 not in [2, 3, 4]
False
>>> 3 not in [4, 5, 6]
True
或者使用元组:
>>> (2, 3) not in [(2, 3), (5, 6), (9, 1)]
False
>>> (2, 3) not in [(2, 7), (7, 3), "hi"]
True
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)