torch.fx.experimental.unification.unification_tools.groupby
-
torch.fx.experimental.unification.unification_tools.groupby(key, seq)[source] -
Группирует коллекцию по ключевой функции
>>> names = ["Alice", "Bob", "Charlie", "Dan", "Edith", "Frank"] >>> groupby(len, names) {3: ['Bob', 'Dan'], 5: ['Alice', 'Edith', 'Frank'], 7: ['Charlie']}>>> iseven = lambda x: x % 2 == 0 >>> groupby(iseven, [1, 2, 3, 4, 5, 6, 7, 8]) {False: [1, 3, 5, 7], True: [2, 4, 6, 8]}Невызываемые ключи означают группировку по атрибуту.
>>> groupby( ... "gender", ... [ ... {"name": "Alice", "gender": "F"}, ... {"name": "Bob", "gender": "M"}, ... {"name": "Charlie", "gender": "M"}, ... ], ... ) {'F': [{'gender': 'F', 'name': 'Alice'}], 'M': [{'gender': 'M', 'name': 'Bob'}, {'gender': 'M', 'name': 'Charlie'}]}Не путать с
itertools.groupbyСм. также
countby
© 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.groupby.html