[Python-ideas] Attribute-Getter Syntax Proposal
Steven D'Aprano
steve at pearwood.info
Fri Mar 8 21:29:51 EST 2019
On Fri, Mar 08, 2019 at 03:43:10PM -0800, Chris Barker - NOAA Federal via Python-ideas wrote:
> >
> > Rather than using map in this way, I would recommend a list comprehension:
>
> Exactly! I really don’t get why folks want to use map() so much when
> the comprehension syntax is often cleaner and easier. It was added for
> a reason :-)
Comprehensions are great for avoiding the need to write verbose lambdas
before calling map:
map(lambda x: x + 1, numbers)
(x + 1 for x in numbers)
but you typically only save a few characters, and you don't even save
that when the function already exists:
map(str.upper, strings)
(s.upper() for s in strings)
So horses for courses.
In my opinion, map() looks nicer when you are calling a pre-existing
named function, and comprehensions look nicer when you have an
expression involving operators which would otherwise require a lambda.
--
Steven
More information about the Python-ideas
mailing list