Mapping None. Why?
David C. Ullrich
dullrich at sprynet.com
Fri Jun 13 07:49:27 EDT 2008
On Thu, 12 Jun 2008 12:05:02 -0700 (PDT), Paddy
<paddy3118 at googlemail.com> wrote:
>
>Iam wondering why the peculiar behavior of map when the function in
>given as None:
If you start with a value x and then apply no function
at all to it, what results is x.
>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?
>
>Thanks, Paddy.
David C. Ullrich
More information about the Python-list
mailing list