List comprehension with if-else

Larry Martell larry.martell at gmail.com
Wed Oct 28 12:25:30 EDT 2015


I'm trying to do a list comprehension with an if and that requires an
else, but in the else case I do not want anything added to the list.

For example, if I do this:

white_list = [l.control_hub.serial_number if l.wblist ==
wblist_enum['WHITE']  else None for l in wblist]

I end up with None in my list for the else cases. Is there a way I can
do this so for the else cases nothing is added to the list?



More information about the Python-list mailing list