[Tutor] Trying to enter text from a file to a Dictionary

Alan Gauld alan.gauld at freenet.co.uk
Sat Jan 28 13:06:43 CET 2006


Hi Bob,

> "list comprehension" (once understood) is often easier to read and more 
> efficient than the for loop.

They are often more efficient but I don't know if I'd ever claim they were 
easier to read than an explicit for loop. Perhaps the most trivial cases
like 

z = [x*2 for x in L] 

and even then I'm not sure that is easier to read than 

z = []
for x in L: z.append(x*2)

And personally I still find map() easier for those cases

z = map(lambda x: x*2, L)

But you do need to be comfortable with lambda for that, and lambda 
is just as hard to grok as list comprehensions! :-)

Alan G.


More information about the Tutor mailing list