[Python-Dev] [rfc] map enhancement

Raymond Hettinger python@rcn.com
Tue, 18 Feb 2003 22:13:44 -0500


> It appears as though you ought to be able to write this as:
> 
>    return map(operator.getitem, data, b=1)
> 
> except that operator.getitem, in common with many builtin functions doesn't 
> accept any keyword arguments.
> 
> This is a pity as it cripples most of the situations where you might 
> otherwise want to use this. e.g. add a constant to elements of a list, or 
> multiply by a constant.

For Py2.3, the itertools module can help:

itertools.imap(operator.__getitem__, data, itertools.repeat(1))


Raymond Hettinger