List comprehension confusion...

Andy Jewell andy at wild-flower.co.uk
Sun Feb 2 11:44:46 CET 2003


WRT map() and list comps:

Which is the most 'pythonic' 
Which is the most efficient?


I personally find list comprehensions quite obfuscated - it's one of the few 
constructs within python which is not immediately obvious to a beginner or 
non-pythonist.

When I read the concept in GVR's Tutorial, I was expecting something much more 
understandable.  For me, map has less mental barriers, but it still doesn't 
seem to say much about what's going on.

I think it has to do with having a for-loop inside a pair of subscript 
braces...

-andyj

On Sunday 02 Feb 2003 4:24 am, Lulu of the Lotus-Eaters wrote:
> Andrew Dalke <adalke at mindspring.com> wrote previously:
> |get the "some_field" attribute of all elements in a list
> |results = [term.some_field for term in data]
>
> Just to throw flame on the fire, I am one of the odd people who find map
> quite readable too:
>
>   result = map(lambda t: t.some_field, data)
>
> Yours, Lulu...







More information about the Python-list mailing list