How to frame two for loops in list comprehension python

后端 未结 6 2133
予麋鹿
予麋鹿 2020-11-28 20:06

I have two lists as below

tags = [u\'man\', u\'you\', u\'are\', u\'awesome\']
entries = [[u\'man\', u\'thats\'],[ u\'right\',u\'awesome\']]

6条回答
  •  半阙折子戏
    2020-11-28 20:23

    tags = [u'man', u'you', u'are', u'awesome']
    entries = [[u'man', u'thats'],[ u'right',u'awesome']]
    
    result = []
    [result.extend(entry) for tag in tags for entry in entries if tag in entry]
    
    print(result)
    

    Output:

    ['man', 'thats', 'right', 'awesome']
    

提交回复
热议问题