problem with interface of operator.itemgetter

dou dou nirvana117 at
Tue Aug 18 18:49:55 CEST 2009

2009/8/17 Simon Forman <sajmikins at>

>  You can use a little helper function to create your itemgetter like this:
> def makeItemGetter(indexes):
>    I = itemgetter(*indexes)
>    if len(indexes) > 1:
>        return I
>    return lambda thing: (I(thing),)
> If indexes contains only one index the itemgetter is wrapped in a
> lambda that turns its output into a tuple.

Thanks. I just thought if the stdlib could support some function like item*s
*getter would be better, it always returns tuple instead of a item or a
tuple of items.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list