Re: yet another list comprehension question

2009-05-05 Thread namekuseijin
2009/5/5 Ricardo Aráoz : > This seems to work for any length tuples : > a = [(1,2), (3,4, 'goes'), (5,None), (6,7, 8, 'as', None), (8, None), (9, 0)] [tup for tup in a if not [e for e in tup if e == None]] > [(1, 2), (3, 4, 'goes'), (9, 0)] Why that extra "for"? KISS >>> a = [(1,2

Re: yet another list comprehension question

2009-05-05 Thread Ricardo Aráoz
namekuseijin wrote: > On May 4, 9:15 am, David Robinow wrote: > >> On Mon, May 4, 2009 at 2:33 AM, namekuseijin >> >> wrote: >> >> ls = [(1,2), (3,4), (5, None), (6,7), (8, None)] >> [(x,y) for (x,y) in ls if y] >> >>> [(1, 2), (3, 4), (6, 7)] >>> >> Nope.

Re: yet another list comprehension question

2009-05-04 Thread namekuseijin
On May 4, 9:15 am, David Robinow wrote: > On Mon, May 4, 2009 at 2:33 AM, namekuseijin > > wrote: > ls = [(1,2), (3,4), (5, None), (6,7), (8, None)] > [(x,y) for (x,y) in ls if y] > > [(1, 2), (3, 4), (6, 7)] > > Nope. That filters out 0 as well as None. Not what the OP asked for. True

Re: yet another list comprehension question

2009-05-04 Thread David Robinow
On Mon, May 4, 2009 at 2:33 AM, namekuseijin wrote: ls = [(1,2), (3,4), (5, None), (6,7), (8, None)] [(x,y) for (x,y) in ls if y] > [(1, 2), (3, 4), (6, 7)] Nope. That filters out 0 as well as None. Not what the OP asked for. -- http://mail.python.org/mailman/listinfo/python-list

Re: yet another list comprehension question

2009-05-04 Thread Arnaud Delobelle
Snorri H writes: > On May 3, 6:13 am, Ross 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 = [(

Re: yet another list comprehension question

2009-05-04 Thread Snorri H
On May 3, 6:13 am, Ross 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

Re: yet another list comprehension question

2009-05-03 Thread namekuseijin
>>> ls = [(1,2), (3,4), (5, None), (6,7), (8, None)] >>> [(x,y) for (x,y) in ls if y] [(1, 2), (3, 4), (6, 7)] -- http://mail.python.org/mailman/listinfo/python-list

Re: yet another list comprehension question

2009-05-03 Thread ma
This isn't list comprehension, but it's something to keep in mind: b = filter(lambda x: None not in x, input_list) On Sat, May 2, 2009 at 10:25 PM, CTO wrote: > On May 2, 10:13 pm, Ross wrote: > > I'm trying to set up a simple filter using a list comprehension. If I > > have a list of tuples,

Re: yet another list comprehension question

2009-05-02 Thread CTO
On May 2, 10:13 pm, Ross 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)]. try

Re: yet another list comprehension question

2009-05-02 Thread Ross
On May 2, 7:21 pm, Chris Rebert wrote: > On Sat, May 2, 2009 at 7:13 PM, Ross 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 wou

Re: yet another list comprehension question

2009-05-02 Thread Chris Rebert
On Sat, May 2, 2009 at 7:13 PM, Ross 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),

yet another list comprehension question

2009-05-02 Thread Ross
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