problem with interface of operator.itemgetter
nirvana117 at gmail.com
Tue Aug 18 18:49:55 CEST 2009
2009/8/17 Simon Forman <sajmikins at gmail.com>
> 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...
More information about the Python-list