Advanced Python list comprehension

后端 未结 6 2394
北海茫月
北海茫月 2021-02-20 14:02

Given two lists:

chars = [\'ab\', \'bc\', \'ca\']
words = [\'abc\', \'bca\', \'dac\', \'dbc\', \'cba\']

how can you use list comprehensions to

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-20 14:45

    Why so complex? This works as well:

    [words[x] for x in range(len(chars)) if chars[x] in words[x]]
    

提交回复
热议问题