proposals for having more fun with map

Ville Vainio ville at
Sat Oct 9 16:30:51 CEST 2004

>>>>> "Tom" == Tom Anderson <twic at> writes:

    Tom> wanting to do all the time, so i either end up throwing lambdas all over
    Tom> the place to glue the dicts into map, or writing a little helper function
    Tom> like so:

    Tom> def functor(dict):
    Tom>     return lambda arg: dict[arg]


#itemgetter: also of course works with dictionaries
data= ( {'name':'fred','score':50},{'name':'betty','score':75})
print map(operator.itemgetter('name'),data)
>>> ['fred', 'betty']

    Tom> this isn't hard, of course, but it's the sort of thing that
    Tom> ought to be done once and only once.

Indeed ;-).

    Tom> again, trivial, but if i'm writing this out in almost every
    Tom> program i write, other people must be too, so it's worth
    Tom> putting in the core.

Actually, the more likely future of map is moving *out* of the core,
to a "functional" module of some sort. List comprehensions (and soon
genexps) are the recommended approach.

Ville Vainio

More information about the Python-list mailing list