proposals for having more fun with map

Ville Vainio ville at spammers.com
Sat Oct 9 10:30:51 EDT 2004


>>>>> "Tom" == Tom Anderson <twic at urchin.earth.li> 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]

See http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305318

#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   http://tinyurl.com/2prnb



More information about the Python-list mailing list