> For the complete documentation index, see [llms.txt](https://docs.verygoodsecurity.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.verygoodsecurity.com/vault/developer-tools/larky/library-api/collections.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
