capturegraph.data.containers.utilities.enumerate
#
enumerate - Enumerated List Access#
Enumerate a List, returning Dicts with index and value fields.
Example
enumerate(items, start=0)
#
Enumerate a List, returning Dicts with index and value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
List[T]
|
The List to enumerate. |
required |
start
|
int
|
The starting index (default 0). |
0
|
Returns:
| Type | Description |
|---|---|
List[Dict]
|
List of Dicts, each with |
Example
photos = List([Path("a.jpg"), Path("b.jpg"), Path("c.jpg")])
enumerate(photos)
# List([
# Dict({'index': 0, 'value': Path('a.jpg')}),
# Dict({'index': 1, 'value': Path('b.jpg')}),
# Dict({'index': 2, 'value': Path('c.jpg')})
# ])
enumerate(photos).map(lambda r: f"photo_{r.index:04d}.jpg")
# List(['photo_0000.jpg', 'photo_0001.jpg', 'photo_0002.jpg'])