yet another list comprehension question
arnodel at googlemail.com
Mon May 4 07:54:15 EDT 2009
Snorri H <a.a.ovtchinnikov at gmail.com> writes:
> On May 3, 6:13 am, Ross <ross.j... at gmail.com> wrote:
>> I'm trying to set up a simple filter using a list comprehension. If I
>> have a list of tuples, a = [(1,2), (3,4), (5,None), (6,7), (8, None)]
>> and I wanted to filter out all tuples containing None, I would like to
>> get the new list b = [(1,2), (3,4),(6,7)].
>> I tried b = [i for i in a if t for t in i is not None] but I get the
>> error that "t is not defined". What am I doing wrong?
> Works as well:
> filter(lambda x:not None in x, your_list)
This is usually spelt 'None not in x'.
More information about the Python-list