map

Hendrik van Rooyen hendrik at microcorp.co.za
Mon Aug 31 04:43:07 EDT 2009


On Monday 31 August 2009 06:55:52 elsa wrote:

8< --------- map question ----------------------------

>
> (Ultimately, I want to call myFunc(myList[0], 'booHoo'), myFunc(myList
> [1], 'booHoo'), myFunc(myList[2], 'booHoo') etc. However, I might want
> to call myFunc(myList[0], 'woo'), myFunc(myList[1], 'woo'), myFunc
> (myList[2], 'woo') some other time).

Here is some heretical advice:

Do not use stuff like map and reduce unless they fit what you want to do 
perfectly, and "JustWorks" the first time.

You have a very clear idea of what you want to do, so why do you not just 
simply write something to do it?

something like this (untested):

def woofer(thefunc,thelist,thething):
	theanswers = []
	for x in thelist:
		theanswers.append(thefunc(x,thething))
	return theanswers

And the advantage is that you do not have to remember what map does...

*ducks away from the inevitable flames*

- Hendrik



More information about the Python-list mailing list