# operator.itemgetter(item) // operator.itemgetter(*items)
# Return a callable object that fetches item from its operand using the operand’s __getitem__() method. If multiple items are specified,
# returns a tuple of lookup values. For example: After f = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3),
# the call g(r) returns (r[2], r[5], r[3]).
# Equivalent to:
def itemgetter(*items):
if len(items) == 1:
item = items[0]
def g(obj):
return obj[item]
else:
def g(obj):
return tuple(obj[item] for item in items)
return g
# The items can be any type accepted by the operand’s __getitem__() method. Dictionaries accept any hashable value. Lists, tuples, and
# strings accept an index or a slice.