Return a bijective pair, (by_id, id_by), where by_id is a sorted tuple of the unique items in iterable, and id_by is a frozendict mapping each item to its id. Each item in iterable must be immutable, otherwise you will get a TypeError about an unhashable object.
Examples
>>> frozenbijection('hello world')
((' ', 'd', 'e', 'h', 'l', 'o', 'r', 'w'), frozendict({' ': 0, 'e': 2, 'd': 1, 'h': 3, 'l': 4, 'o': 5, 'r': 6, 'w': 7}))
>>> frozenbijection(['world', 'wide', 'hello', 'world'])
(('hello', 'wide', 'world'), frozendict({'wide': 1, 'hello': 0, 'world': 2}))
Example of error on mutable items
>>> frozenbijection(['world', 'wide', 'hello', 'world', ['this item is a mutable list']])
Traceback (most recent call last):
...
frozenbijection(('world', 'wide', 'hello', 'world', ['this item is a mutable list']))
File "<stdin>", line ###, in frozenbijection
File "<stdin>", line ###, in sorteduniquetuple
TypeError: ...unhashable...
Return a new list with length elements each set to initializer (default None).
>>> listn(3)
[None, None, None]
>>> listn(4, 0)
[0, 0, 0, 0]
Return a tuple of the sorted set of unique items it iterable. Each item in iterable must be immutable, otherwise you will get a TypeError about an unhashable object.
Examples
>>> sorteduniquetuple('hello world')
(' ', 'd', 'e', 'h', 'l', 'o', 'r', 'w')
>>> sorteduniquetuple(['world', 'wide', 'hello', 'world'])
('hello', 'wide', 'world')
Example of error on mutable items
>>> sorteduniquetuple(['world', 'wide', 'hello', 'world', ['this item is a mutable list']])
Traceback (most recent call last):
...
sorteduniquetuple(['world', 'wide', 'hello', 'world', ['this item is a mutable list']])
File "<stdin>", line ###, in sorteduniquetuple
TypeError: ...unhashable...
Return a new tuple with length elements each set to initializer (default None).
>>> tuplen(3)
(None, None, None)
>>> tuplen(4, 0)
(0, 0, 0, 0)
Return a tuple containing length new, empty lists.
>>> tuplenoflist(3)
([], [], [])