【问题标题】:Find lists in list of lists whose length is equal to certain value [duplicate]在长度等于某个值的列表列表中查找列表[重复]
【发布时间】:2018-05-20 19:14:34
【问题描述】:

我正在使用 python 2.7 并且想在长度等于某个值的列表列表中查找列表

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

结果:列表长度不等于 3

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

【问题讨论】:

    标签: python python-2.7 list


    【解决方案1】:

    一种方法是使用列表推导:

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

    【讨论】:

    • 谢谢,成功了!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 2019-11-10
    • 2019-01-19
    • 2020-12-09
    • 2021-01-23
    • 2013-11-17
    相关资源
    最近更新 更多