A "for" with "list" question.

Ante Bagaric aurin42 at yahoo.com
Tue Sep 3 10:26:54 CEST 2002


> >>> [item for item in a if item in b]
> [1, 2]
>
> That third line is a list comprehension.

>>> a = [0, 1, 2]
>>> b = [1, 2, 3]
>>> [i for i in a if i in b] + [i for i in a + b if i not in a or i not in
b]
[1, 2, 0, 3]

:)







More information about the Python-list mailing list