[Tutor] Use of List Comprehension? (original) (raw)
Alan Gauld alan.gauld at blueyonder.co.uk
Thu Jul 29 22:53:30 CEST 2004
- Previous message: [Tutor] Use of List Comprehension?
- Next message: [Tutor] Python for Windows: module re, re.LOCALE different for Idle and p ython shell?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Previous message: [Tutor] Use of List Comprehension?
- Next message: [Tutor] Python for Windows: module re, re.LOCALE different for Idle and p ython shell?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]