I have two lists looking like:
list1 = [\'a\',\'a\',\'b\',\'b\',\'b\',\'c\',\'d\',\'e\',\'e\',\'g\',\'g\']
list2 = [\'a\',\'c\',\'z\',\'y\']
From Python 3 onwards use itertools.filterfalse
>>> import itertools
>>> list1 = ['a','a','b','b','b','c','d','e','e','g','g']
>>> list2 = ['a','c','z','y']
>>> list(itertools.filterfalse(lambda x:x not in list2,list1))
['a', 'a', 'c']
The list call is necessary as filterfalse returns an itertools object.
You can also use the filter function
>>> list(filter(lambda x: x in list2 , list1))
['a', 'a', 'c']