substituting list comprehensions for map()
Ben Finney
ben+python at benfinney.id.au
Mon Nov 2 17:14:05 EST 2009
J Kenneth King <james at agentultra.com> writes:
> Steven D'Aprano <steven at REMOVE.THIS.cybersource.com.au> writes:
>
> > from operator import add
> > map(add, operandlist1, operandlist2)
>
> This is the best solution so far.
Strange to say it's a solution, when it doesn't solve the stated
problem: to replace use of ‘map()’ with a list comprehension.
> I understand the OP was asking for it, but list comprehensions aren't
> the best solution in this case... it would just be line noise.
I disagree; a list comprehension is often clearer than use of ‘map()’
with a lambda form, and I find it to be so in this case.
--
\ “He may look like an idiot and talk like an idiot but don't let |
`\ that fool you. He really is an idiot.” —Groucho Marx |
_o__) |
Ben Finney
More information about the Python-list
mailing list