[Tutor] map, filter and lambda functions

Ignacio Vazquez-Abrams ignacio@openservices.net
Thu, 23 Aug 2001 00:27:17 -0400 (EDT)


On Wed, 22 Aug 2001, Sheila King wrote:

> Are you sure that you can do this without lambda? I tried today, and
> couldn't get it to work without lambda.
>
> >>> mylist
> ['a', 'b', 'c', '']
> >>> mylist = map(string.upper(x), mylist)
> Traceback (most recent call last):
>   File "<pyshell#6>", line 1, in ?
>     mylist = map(string.upper(x), mylist)
> NameError: name 'x' is not defined
> >>> mylist = map(string.upper(), mylist)
> Traceback (most recent call last):
>   File "<pyshell#7>", line 1, in ?
>     mylist = map(string.upper(), mylist)
> TypeError: upper() takes exactly 1 argument (0 given)
> >>>
>
> If I do it with no argument, it complains that it requires an argument.
> If I put an argument there, it complains that it has never heard of that
> variable before.

That's because the first argument to map has to be a function object; you'd
have to use map(string.upper, mylist).

-- 
Ignacio Vazquez-Abrams  <ignacio@openservices.net>