且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查Python列表中是否存在元组?

更新时间:2021-11-23 19:01:34

由于'1' != 1以及['1','2'] != [1,2] 如果您希望它正常工作,请尝试:

The code does not work because '1' != 1 and, consequently, ['1','2'] != [1,2] If you want it to work, try:

a=[['1','2'],['1','3']]
for i in range(3):
    for j in range(3):
        if [str(i), str(j)] in a: # Note str
            print a

(但是使用in或如上所述的集合更好)

(But using in or sets as already mentioned is better)