This isn't list comprehension, but it's something to keep in mind:<div><br></div><div>b = filter(lambda x: None not in x, input_list)<br>
<br><br><div class="gmail_quote">On Sat, May 2, 2009 at 10:25 PM, CTO <span dir="ltr"><<a href="mailto:debatem1@gmail.com">debatem1@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On May 2, 10:13 pm, Ross <<a href="mailto:ross.j...@gmail.com">ross.j...@gmail.com</a>> wrote:<br>
> I'm trying to set up a simple filter using a list comprehension. If I<br>
> have a list of tuples, a = [(1,2), (3,4), (5,None), (6,7), (8, None)]<br>
> and I wanted to filter out all tuples containing None, I would like to<br>
> get the new list b = [(1,2), (3,4),(6,7)].<br>
<br>
</div>try this:<br>
<br>
b = [i for i in a if None not in i]<br>
<div class="im"><br>
> I tried b = [i for i in a if t for t in i is not None] but I get the<br>
> error that "t is not defined". What am I doing wrong?<br>
<br>
</div>You've got a "for" and an "if" backwards. t isn't defined when the if<br>
tries to evaluate it.<br>
<div><div></div><div class="h5"><br>
<br>
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br></div>