map is useless!

Lie Ryan lie.1296 at gmail.com
Sun Jun 6 15:27:43 EDT 2010


On 06/07/10 03:22, rantingrick wrote:
> On Jun 6, 12:02 pm, Alain Ketterlin <al... at dpt-info.u-strasbg.fr>
> wrote:
>> rantingrick <rantingr... at gmail.com> writes:
>> I've not used map since I learned about list comprehensions.
> 
> Thats has been my experienced also. Actually i've been at Python for
> O... about 2 years now and i don't think i've ever used map in a
> script even one time until a month or so ago. After a few unit tests
> it seems i was right all along. But the funny thing is in other
> languages i use map all the time. It's just too awkward in Python and
> i wish it were not so... Oh well?

In the most naive uses, map appears to have no advantage over list
comprehension; but one thing that map can do that list comprehension
still can't do without a walk around the park:

def foo(func, args):
    g = lambda x: x+1
    return [func(g, x) for x in args]

foo(map, [[4, 6, 3], [6, 3, 2], [1, 3, 5]])

I'm not going to argue how often that would be useful though.



More information about the Python-list mailing list