Python doesn’t allow dictionaries to be used as keys in other dictionaries. Is there a workaround for using non-nested dictionaries as keys?
The general problem with more complicated non-hashable objects and my specific use case has been moved here. My original description of my use case was incorrect.
If you have a really immutable dictionary (although it isn’t clear to me why you don’t just use a list of pairs: e.g.
[('content-type', 'text/plain'), ('host', 'example.com')]), then you may convert yourdictinto:A tuple of pairs. You’ve already done that in your question. A
tupleis required instead oflistbecause the results rely on the ordering and the immutability of the elements.A frozen set. It is a more suitable approach from the mathematical point of view, as it requires only the equality relation on the elements of your immutable
dict, while the first approach requires the ordering relation besides equality.