查找长度等于特定值的列表列表中的列表

时间:2018-05-20 19:14:35

标签: python python-2.7 list

我使用python 2.7并希望在长度等于某个值的列表列表中找到列表

EX: [['abc,'orange,'NYC'],['def','apple','NYC','USA'],['xyz','california'],['qwe','mango','USA']......]]

结果:列表不等于长度3

['def','apple','NYC','USA'],['xyz','california']

1 个答案:

答案 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']]