Is there an idiom for this?

KP kai.peters at gmail.com
Thu Dec 24 17:32:55 EST 2015


Thanks Paul, you just pointed out one of my blonder moments: 

I actually want all nested dicts one by one, but not the one with the 'c' key...



On Thursday, 24 December 2015 14:15:45 UTC-8, Paul Rubin  wrote:
> KP writes:
> > for config in cfg: 
> >     if config != 'c': 
> >         print config 
> >
> > Is there an idiom that combines the 'for...' & the 'if..' lines into one? 
> 
> Maybe you actually want
> 
>   print [config for config in cfg if config != 'c']
> 
> That prints all the relevant keys as a list, rather than one per line.




More information about the Python-list mailing list