problem with interface of operator.itemgetter
dou dou
nirvana117 at gmail.com
Tue Aug 18 12:49:55 EDT 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...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090819/06f2bcbf/attachment-0001.html>
More information about the Python-list
mailing list