list iteration if statement

MRAB google at mrabarnett.plus.com
Fri Jan 2 22:12:38 EST 2009


alex goretoy wrote:
> Thank you Steve and MRAB,
> 
> This is what I was looking for:
> 
>  [[v.append(j) for j in i if j != 0] for i in self.value]
> 
> the value is actually stored as a string so I would need to check if it 
> is "0". I do have one more question about list comprehension though. 
> After doing this I get an unwanted list of None how do I make it 
> disappear or not return this list. Would I have to be modifying it in 
> place for this to happen? Wouldn't modifying it in place potentially 
> overwrite some other values? I just don't want it to return [[None], 
> [None, None], [None, None], [None]]
> 
> You guys rock, thanks for helping me learn python.
> 
No, it's Python that rocks. ;-)

[snip]



More information about the Python-list mailing list