List comp help

Joseph L. Casale jcasale at activenetwerx.com
Sun Jul 14 20:09:45 CEST 2013


> Yeah, it's remarkably easy too! Try this:
>
> [(k, x) for k, v in my_dict.items() for x in v or [None]]
>
> An empty list counts as false, so the 'or' will then take the second option, and iterate over the one-item list with > > None in it.

Right, I overlooked that!

Much appreciated,
jlc



More information about the Python-list mailing list