| |
- flatten(lst)
- Flatten an iterable.
All contained tuples, lists, deques and sets are replaced by their
elements and flattened as well.
>>> l = [1, 2, [3, [4], [5, 6]], 7]
>>> list(flatten(l))
[1, 2, 3, 4, 5, 6, 7]
>>> list(flatten(()))
[]
- unique(iterable)
- Return an iterable of the same type which contains unique items.
This function assumes that:
type(iterable)(list(iterable)) == iterable
which is true for tuples, lists and deques (but not for strings)
>>> unique([1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 1, 1, 2])
[1, 2, 3, 4]
>>> unique(('w', 't', 't', 'f', 't', 'w'))
('w', 't', 'f')
|