list iteration if statement
MRAB
google at mrabarnett.plus.com
Fri Jan 2 21:07:57 EST 2009
alex goretoy wrote:
> Hello All,
>
> I'm doing this in my code
>
> [[v.append(j) for j in i] for i in self.value]
>
> if works and all, but I need to add a if statement in the mix. Can't
> seem to remember the syntax to do so and everything I've tried seems to
> fail. How do I add a check to see if j is not int("0") then append to v
> list? Thank you in advance. -A
>
By:
if j is not int("0")
I assume you mean:
if j != int("0")
or just:
if j != 0
The list comprehension is:
[[v.append(j) for j in i if j != 0] for i in self.value]
BWT, do you know that v.append(j) modifies v in-place and returns None,
so the result of the list comprehension is a list of lists of None?
More information about the Python-list
mailing list