# collections

Starlark module for working with collections library.

This module implements specialized container datatypes providing alternatives to Python's general purpose built-in containers, dict, list, set, and tuple.

Similar to [collections in Python](https://docs.python.org/3/library/collections.html).

## collections.after\_each(separator, iterable)

Inserts separator after each item in iterable.

**Parameters:**

* **separator** - the value to insert after each item in iterable.
* **iterable** - the list into which to intersperse the separator.

*Returns:* a new list with separator after each item in iterable.

## collections.before\_each(separator, iterable)

Inserts separator before each item in iterable.

**Parameters:**

* **separator** - the value to insert before each item in iterable.
* **iterable** - the list into which to intersperse the separator.

*Returns:* a new list with separator before each item in iterable.

## collections.namedtuple(typename, field\_names, rename=False, defaults=None, module=None)

*Returns:* a new subclass of tuple with named fields.

Examples:

```python
Point = namedtuple('Point', ['x', 'y'])
Point.__doc__                # docstring for the new class
'Point(x, y)'
p = Point(11, y=22)          # instantiate with positional args or keywords
p[0] + p[1]                  # indexable like a plain tuple
33
x, y = p                     # unpack like a regular tuple
x, y
(11, 22)
p.x + p.y                    # fields also accessible by name
33
d = p._asdict()              # convert to a dictionary
d['x']
11
Point(**d)                   # convert from a dictionary
Point(x=11, y=22)
p._replace(x=100)            # _replace() is like str.replace() but targets named fields
Point(x=100, y=22)
```

## collections.uniq(iterable)

*Returns:* a list of unique elements in iterable. Requires all the elements to be hashable.

**Parameters:**

**iterable** – an iterable to filter.

*Returns:* a new list with all unique elements from iterable.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.verygoodsecurity.com/vault/developer-tools/larky/library-api/collections.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
