[Python-Dev] [rfc] map enhancement
Ludovic Aubry
Ludovic.Aubry@logilab.fr
Wed, 19 Feb 2003 11:22:07 +0100
This is nice,
The strongest objection regarding using
map(f,L,x=K) is that there is no clear way of telling
the reader that the keyword argument will be passed as a constant
Your solution for itertools can work with map too:
def repeat(v,n):
while n:
yield v
n-=1
map(f,L,repeat(K,len(L)))
would do the trick
As a nice addition it also allows one to put constants anywhere
in the argument list for f
Thanks for the idea
On Tue, Feb 18, 2003 at 10:13:44PM -0500, Raymond Hettinger wrote:
> > 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
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev@python.org
> http://mail.python.org/mailman/listinfo/python-dev
--
Ludovic Aubry LOGILAB, Paris (France).
http://www.logilab.com http://www.logilab.fr http://www.logilab.org