Spec-Zone.ru › PyTorch 2.14

torch.fx.experimental.unification.unification_tools.get_in

torch.fx.experimental.unification.unification_tools.get_in(keys, coll, default=None, no_default=False) [source]

Возвращает coll[i0][i1]…[iX], где [i0, i1, …, iX]==keys.

Если coll[i0][i1]…[iX] не найдено, возвращает default, если не указано no_default; в этом случае возникает исключение KeyError или IndexError.

get_in — это обобщение operator.getitem для вложенных структур данных, таких как словари и списки.

>>> transaction = {
...     "name": "Alice",
...     "purchase": {"items": ["Apple", "Orange"], "costs": [0.50, 1.25]},
...     "credit card": "5555-1234-1234-1234",
... }
>>> get_in(["purchase", "items", 0], transaction)
'Apple'
>>> get_in(["name"], transaction)
'Alice'
>>> get_in(["purchase", "total"], transaction)
>>> get_in(["purchase", "items", "apple"], transaction)
>>> get_in(["purchase", "items", 10], transaction)
>>> get_in(["purchase", "total"], transaction, 0)
0
>>> get_in(["y"], {}, no_default=True)
Traceback (most recent call last):
    ...
KeyError: 'y'

См. также

itertoolz.get operator.getitem

Тип возвращаемого значения:

object

© 2026, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://docs.pytorch.org/docs/2.14/generated/torch.fx.experimental.unification.unification_tools.get_in.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API