我有两个清单如下
tags = [u'man', u'you', u'are', u'awesome'] entries = [[u'man', u'thats'],[ u'right',u'awesome']]
我想提取物项从entries当他们在tags:
entries
tags
result = [] for tag in tags: for entry in entries: if tag in entry: result.extend(entry)
如何将两个循环写为单行列表理解?
应该这样做:
[entry for tag in tags for entry in entries if tag in entry]