searching within nested list in python

前端 未结 4 673
鱼传尺愫
鱼传尺愫 2021-01-13 18:56

I have a list:

l = [[\'en\', 60, \'command\'],[\'sq\', 34, \'komand\']]

I want to search for komand or sq and get

4条回答
  •  有刺的猬
    2021-01-13 19:05

    Yes:

    has_oneof = lambda *patterns: lambda: values any(p in values for p in patterns)
    result = itertools.ifilter(has_oneof('komand', 'sq'), l).next()
    print result # prints ['sq', 34, 'komand']
    

提交回复
热议问题