roboto.collection_utils#
Module Contents#
- roboto.collection_utils.T#
- class roboto.collection_utils.defaultlist(factory)#
-
Like collections.defaultdict, but for list.
Automatically supplies a default value when you access an index that hasn’t been set or is out of bounds, without raising an IndexError.
Examples
>>> dl = defaultlist[int](factory=lambda: 0) >>> dl[5] += 1 # Automatically extends list with 0s up to index 5 >>> print(dl) # [0, 0, 0, 0, 0, 1]
- Parameters:
factory (Callable[[], T])
- factory#
- roboto.collection_utils.get_by_path(target, key_path)#
Access a key path in a mapping. Returns
Noneif any part of the path is not found or traverses through an object that is not a mapping.- Parameters:
target (collections.abc.Mapping[Any, Any])
key_path (collections.abc.Sequence[Any])
- Return type:
Any