List comprehensions' ugliness (Was: Re: How to explain exactly what "def" does?)

Dave Brueck dave at
Wed Feb 5 23:40:30 CET 2003

On Wed, 5 Feb 2003, Hans Nowak wrote:

> I'm sure there are better (worse?) examples of list comp abuse.

>>> [a+b+c for a in "hard" for b in "to read" if b != 'e' for c in "code"
if c!='o' if len((a+b+c).split()) == 1]

['htc', 'htd', 'hte', 'hoc', 'hod', 'hoe', 'hrc', 'hrd', 'hre', 'hac',
'had', 'hae', 'hdc', 'hdd', 'hde', 'atc', 'atd', 'ate', 'aoc', 'aod',
'aoe', 'arc', 'ard', 'are', 'aac', 'aad', 'aae', 'adc', 'add', 'ade',
'rtc', 'rtd', 'rte', 'roc', 'rod', 'roe', 'rrc', 'rrd', 'rre', 'rac',
'rad', 'rae', 'rdc', 'rdd', 'rde', 'dtc', 'dtd', 'dte', 'doc', 'dod',
'doe', 'drc', 'drd', 'dre', 'dac', 'dad', 'dae', 'ddc', 'ddd', 'dde']


More information about the Python-list mailing list