substituting list comprehensions for map()
ben+python at benfinney.id.au
Mon Nov 2 23:14:05 CET 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 |
More information about the Python-list