MCPcopy Index your code
hub / github.com/python/cpython / itemgetter

Class itemgetter

Lib/operator.py:279–308  ·  view source on GitHub ↗

Return a callable object that fetches the given item(s) from its operand. 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])

Source from the content-addressed store, hash-verified

277 return self.__class__, self._attrs
278
279class itemgetter:
280 """
281 Return a callable object that fetches the given item(s) from its operand.
282 After f = itemgetter(2), the call f(r) returns r[2].
283 After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])
284 """
285 __slots__ = ('_items', '_call')
286
287 def __init__(self, item, /, *items):
288 if not items:
289 self._items = (item,)
290 def func(obj):
291 return obj[item]
292 self._call = func
293 else:
294 self._items = items = (item,) + items
295 def func(obj):
296 return tuple(obj[i] for i in items)
297 self._call = func
298
299 def __call__(self, obj, /):
300 return self._call(obj)
301
302 def __repr__(self):
303 return '%s.%s(%s)' % (self.__class__.__module__,
304 self.__class__.__name__,
305 ', '.join(map(repr, self._items)))
306
307 def __reduce__(self):
308 return self.__class__, self._items
309
310class methodcaller:
311 """

Callers 15

_partial_prepare_mergerFunction · 0.90
fmeanFunction · 0.90
_rankFunction · 0.90
paramsMethod · 0.90
test_small_stabilityMethod · 0.90
test_mergeMethod · 0.90
write_pot_fileFunction · 0.90
calcFunction · 0.90
calc_pair_count_tableFunction · 0.90
calc_deferred_by_tableFunction · 0.90
calc_misses_by_tableFunction · 0.90

Calls

no outgoing calls

Tested by 3

test_small_stabilityMethod · 0.72
test_mergeMethod · 0.72
test_itemgetterMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…