itertools, functools, file enhancement ideas

Klaas mike.klaas at gmail.com
Tue Apr 10 21:26:29 CEST 2007


On Apr 8, 9:34 am, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> rdhettin... at gmail.com writes:

> > >       a) def flip(f): return lambda x,y: f(y,x)
> > Curious resemblance to:
> >    itemgetter(1,0)
>
> Not sure I understand that.

I think he read it as lambda (x, y): (y, x)

More interesting would be functools.rshift/lshift, that would rotate
the positional arguments (with wrapping)

def f(a, b, c, d, e):
...
rshift(f, 3) --> g, where g(c, d, e, a, b) == f(a, b, c, d, e)

Still don't see much advantage over writing a lambda (except perhaps
speed).

-Mike




More information about the Python-list mailing list