---
sidebar:
  label: roboto.collection_utils
  order: 6
title: roboto.collection_utils
---
## Module Contents

### T

```python
roboto.collection_utils.T
```

`from roboto.collection_utils import T`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/collection_utils.py#L11-L11)

### defaultlist

```python
class roboto.collection_utils.defaultlist(factory: Callable[[], T])
```

`from roboto.collection_utils import defaultlist`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/collection_utils.py#L28-L77)

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**

```python
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**

### get_by_path()

```python
def roboto.collection_utils.get_by_path(
    target: collections.abc.Mapping[Any, Any],
    key_path: collections.abc.Sequence[Any],
) -> Any
```

`from roboto.collection_utils import get_by_path`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/collection_utils.py#L14-L25)

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]`)

**Returns**

- `Any`
