Saturday, 31 August 2013

How to frame two for loops in list comprehension python

How to frame two for loops in list comprehension python

I have two lists as below
tags = [u'man', u'you', u'are', u'awesome']
entries = [[u'man', u'thats'],[ u'right',u'awesome']]
result = []
for tag in tags:
for entry in entries:
if tag in entry:
result.append(entry)
How to do the above logic using list comprehension in a single line, and
that should be ultimate and very fast ?

No comments:

Post a Comment