Ken Oliver wrote:
> I seem to stumble often with things like
> 
> nz = [ (k,v) for k,v in lst if v!=0]
> 
> I have not been able to wrap my brain around the parentheses. I see
> it
as reasonable to have the () around the k,v in the tuple in the first
instance, but I feel like they should also be around k,v in the second
instance (the for clause).

You can write it as [ (k,v) for (k,v) in lst if v!=0] if you prefer.

> Now can you do it all in one statement? Hehe. Just teasing.

I hope it's obvious how to do that...

Kent
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to