Nobody nobody at
Mon Aug 31 22:20:55 CEST 2009

On Sun, 30 Aug 2009 21:55:52 -0700, elsa wrote:

> say I have a list, myList. Now say I have a function with more than
> one argument:
> myFunc(a, b='None')
> now, say I want to map myFunc onto myList, with always the same
> argument for b, but iterating over a:
> map(myFunc(b='booHoo'), myList)
> Why doesn't this work?

You're passing the result of (incorrectly) calling myFunc to map(), but
you need to pass a function.

> is there a way to make it work?

If you need to construct a simple function on-the-fly, you can use a
lambda form:

	map(lambda x: myFunc(x, b='booHoo'), myList)

Or you could use a list comprehension:

	[myFunc(x, b='booHoo') for x in myList]

More information about the Python-list mailing list