[Tutor] Use of List Comprehension?
Alan Gauld
alan.gauld at blueyonder.co.uk
Thu Jul 29 22:53:30 CEST 2004
> I was wondering under which circumstances one might use list
> comprehension.
You use it to build lists.
> Does it have any effect on computation time,
It usually performs faster than writing the equivalent Python code
because the comprehensions are implemented in C.
> used for a matter of simplicity (though could be less easier to
read)?
Some people seem to find comprehensions quite straightforward,
personally I still prefer the older map/filter/reduce functions
for readability, but that's because I'm used to their names in math.
I'm slowly getting used to reading comprehensions but I still don't
like the typical
[x for x ....]
syntax, I'd have liked to see some kind of separator,
like say a colon:
[x: for x...]
My opinion FWIW,
Alan G.
More information about the Tutor
mailing list