tet.util.collections module

Collection utilities for Tet applications.

This module provides utility functions for working with collections.

Example

Flattening nested iterables:

from tet.util.collections import flatten

nested = [1, [2, 3, [4, 5]], 6]
flat = list(flatten(nested))
# flat == [1, 2, 3, 4, 5, 6]

# Strings are not exploded
with_strings = ["hello", ["world", ["!"]]]
flat = list(flatten(with_strings))
# flat == ["hello", "world", "!"]
tet.util.collections.flatten(l)[source]

Flattens a deeply nested iterable, but does not explode str, bytes. From http://stackoverflow.com/a/2158532/

Parameters:

l – the list

Returns:

a generator of flattened items