Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.python Subject: Re: Is there an idiom for this? Date: Thu, 24 Dec 2015 14:15:33 -0800 Organization: A noiseless patient Spider Lines: 12 Message-ID: <878u4jh4sa.fsf@nightsong.com> References: <08289d1a-a032-490f-963f-cc40ec0d81e3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="7fb8b9b5119ed656382b2cea88166c4f"; logging-data="12322"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+nBsz5l9qde67QEfiRdpRn" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:R8RKtStT1rrgI72BE5EqNwbj4NE= sha1:MI52EZVBqh0g5cId9Ru7UZROsKM= Xref: csiph.com comp.lang.python:100837 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.