Is there an idiom for this?

Paul Rubin no.email at nospam.invalid
Thu Dec 24 17:15:33 EST 2015


KP <kai.peters at gmail.com> 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