Skip to content
Roboto
Esc
↑↓navigate↵open⌘Jpreview
On this page

roboto.collection_utils

Module Contents

T

roboto.collection_utils.T#View Source

defaultlist

class roboto.collection_utils.defaultlist(factory)#View Source

Bases: list[T], Generic[T]

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.

Usage

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]

Attributes

defaultlist.factory

factory #

get_by_path()

roboto.collection_utils.get_by_path(target, key_path)#View Source

Access a key path in a mapping. Returns None if 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

Was this page helpful?