我使用python 2.7并希望在长度等于某个值的列表列表中找到列表
EX: [['abc,'orange,'NYC'],['def','apple','NYC','USA'],['xyz','california'],['qwe','mango','USA']......]]
结果:列表不等于长度3
['def','apple','NYC','USA'],['xyz','california']
答案 0 :(得分:0)
一种方法是使用列表理解:
A = [['abc','orange','NYC'],['def','apple','NYC','USA'],
['xyz','california'],['qwe','mango','USA']]
res = [i for i in A if len(i) != 3]
print(res)
[['def', 'apple', 'NYC', 'USA'], ['xyz', 'california']]