I have a defaultdict(list)
which I'd like to make immutable so that I can add objects of this type to a set. I have an idea as to how I can make it immutable, but it would require me write a few lines of code. Is there not a simpler way of doing this in python?
Isn't it common in python to populate, for example a defaultdict(list)
, while parsing a piece of data before freezing it once the parsing is complete?
Its also the case that an object can be of type tuple but can't be used as a dict key, for example:
>>> a = ([1,2],[2,3])
>>> type(a)
<type 'tuple'>
>>> d = dict()
>>> d[a] = 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
Why there exists a tuple of lists in python is also something I dont understand.