# Mapping None. Why?

Diez B. Roggisch deets at nospam.web.de
Thu Jun 12 21:32:10 CEST 2008

```Paddy schrieb:
> Iam wondering why the peculiar behavior of map when the function in
> given as None:
>
> Help on built-in function map in module __builtin__:
>
> map(...)
>     map(function, sequence[, sequence, ...]) -> list
>
>     Return a list of the results of applying the function to the items
> of
>     the argument sequence(s).  If more than one sequence is given, the
>     function is called with an argument list consisting of the
> corresponding
>     item of each sequence, substituting None for missing values when
> not all
>     sequences have the same length.  If the function is None, return a
> list of
>     the items of the sequence (or a list of tuples if more than one
> sequence).
>
>
> It seems as the action whith none is the same as using a function of
>   lambda *x: x
> As in the following example:
>
>>>> l1 = 'asdf'
>>>> l2 = 'qwertyuip'
>>>> l3 = range(3)
>>>> l1,l2,l3
> ('asdf', 'qwertyuip', [0, 1, 2])
>>>> map(lambda *x: x, l1,l2,l3) == map(None, l1,l2,l3)
> True
>
>
> On looking up map on Wikipedia there is no mention of this special
> behaviour,
> So my question is why?

Because it is undefined what should happen in case of no function given
at all - and because there is no identity function in python
pre-defined, it could be considered sensible to make None the quivalent
of that function.

And it only follows that *if* you imply a function even though there is
None given, that the passed tuple is returned.

I don't see anything on wikipedia that defines any other behavior.

Diez

Diez

```