this type is impossible in Python
this type is impossible in Python
You can have a dictionary which maps to strings, you can have a list containing sets of frozensets of ints, but you can’t have a dictionary of unhashable types.
Python 3.8.5 (default, Sep 4 2020, 02:22:02)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
>>> d=dict()
>>> l=[1,2,3]
>>> d[l]=42
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'Apparently there are ways to monkey patch core types, so you could probably add a __hash__ method to list…
FirstNameType = str
(But don't use ints for postal codes, even if the postal codes are numeric)Maybe in the US. In Canada, they are 6 characters of letter-digit-letter-digit-letter-digit (in regex: /((?:[A-Z][0-9]){3})/)
FirstName = NewType('FirstName', str)
PostalCode = NewType('PostalCode', str)
[1] https://docs.python.org/3/library/typing.html#newtype[== do we have something like Java???]
I use type annotations solely as means of documenting code, with the added benefit of having autosuggest work all of the time. I am one of those guys who put a lot of comments in their code.
I could maybe see something like this as an intermediary result of parsing some horrible, nested obscure message format (except the dict, that baffles me unless the key-value types are reversed?)
If the need exists for a list of lists then it exists for a set of sets.
An example of this is finding all combinations possible non ordered groups of letters given a collection of letters: abadfjiik.
A typical algorithm will produce dupes. But if your accumulator is a set of frozen sets you can produce a result with no dupes.