2 ms·
Python probably has a set type, but a common general use case for use an associative array as a key is when making a set. dict = { "foo" : "bar" } set = { dic
by PopeDotNinja 8y ago
Python probably has a set type, but a common general use case for use an associative array as a key is when making a set.
dict = { "foo" : "bar" }
set = { dict : true }
set.has_key?(dict) # true
I'm sure there are other use cases where dict keys can be convenient.
- Scarblac 8y agoYes, Python has both a set type and the immutable "frozenset" type, that can be used as a dictionary key. someset = {"one", "two", "three"} "one" in someset # true frozen = frozenset(someset) somedict = {frozen: "example"} frozen in somedict # true somedict[frozen] # "example"