Is this an inconsistency?

Remco Gerlich scarblac at pino.selwerd.nl
Mon Mar 26 07:32:05 EST 2001


apardon at trout.vub.ac.be <apardon at trout.vub.ac.be> wrote in comp.lang.python:
>   map(None , list)
> 
> Doesn't turn into a list of singletons but
> just returns the list.
> 
> This seems a bit odd to me because if you
> use apply with a single parameter function
> the second argument has to be either a singleton
> or a list with one element.
> 
> 
> My question now: Is this behaviour changed in
> the following versions? If not, wouldn't it be
> more consistent if it was?
 
It's inconsistent if you see it this way, yes. On the other hand, if you
think of different functions to call map with that take one argument, it's
pretty nice that map(None, l) just returns l unchanged. It would be weird if
the 'None' function made tuples. (Some people would see that an exception or
returning a list of Nones would be more consistent, but that would be
useless).

With multiple lists, returning the list of tuples is the closest thing you
can do to returning the arguments to the 'None-function' unchanged.

In 2.0 and up, there is the zip() function, which does exactly what you want.

>>> zip(range(3))
[(0,), (1,), (2,)]
>>> zip(range(3),"abc")
[(0, 'a'), (1, 'b'), (2, 'c')]

-- 
Remco Gerlich



More information about the Python-list mailing list