Looking under Python's hood: Will we find a high performance or clunky engine?

alex23 wuwei23 at gmail.com
Tue Jan 24 01:44:19 EST 2012


On Jan 24, 4:56 am, 88888 Dihedral <dihedral88... at googlemail.com>
wrote:
> 在 2012年1月23日星期一UTC+8上午2时01分11秒,Robert Kern写道:
> >    [line.strip('\n') for line in f]
>
> This is more powerful by turning an object to be iterable.
> But the list comprehension violates the basic operating
> principle of the iteratee chaining rule in programming.

Thankfully, the syntax is almost identical for generators, which are
chain-able:

    noEOLs = (line.strip('\n') for line in f)
    txtSuffix = (line for line in noEOLs if line.endswith('txt'))
    ...etc

> I know manny python programmers just abandon the list comprehension
> in non-trivial processes.

Really? Observation of the python mailing list indicates the opposite:
people seem inclined to use them no matter what.

Also: PLEASE STOP DOUBLE POSTING.



More information about the Python-list mailing list