Added itemgetter and attrgetter to operator.

This commit is contained in:
Jeremy Fincher 2004-03-01 18:15:21 +00:00
parent e04489e18a
commit b9483aee3b

View File

@ -149,6 +149,15 @@ def rsplit(s, sep=None, maxsplit=-1):
L.reverse() L.reverse()
return [s[::-1] for s in L] return [s[::-1] for s in L]
import operator
def itemgetter(i):
return lambda x: x[i]
def attrgetter(attr):
return lambda x: getattr(x, attr)
operator.itemgetter = itemgetter
operator.attrgetter = attrgetter
for name in exported: for name in exported:
__builtins__[name] = globals()[name] __builtins__[name] = globals()[name]