yet another list comprehension question

ma mabdelkader at gmail.com
Sun May 3 03:07:41 EDT 2009


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 <debatem1 at gmail.com> wrote:

> On May 2, 10:13 pm, 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)].
>
> try this:
>
> b = [i for i in a if None not in i]
>
> > 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?
>
> You've got a "for" and an "if" backwards. t isn't defined when the if
> tries to evaluate it.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090503/b48a7e2a/attachment-0001.html>


More information about the Python-list mailing list