I'm using frozensets to keep the keys of my dictionary to take an advantage of union, difference and intersection operations. But when I'm trying to retrieve values by keys from the dictionary through dict.get() it yields a None value.
newDict = {'a': 1, 'b': 2, 'c': 3, 'd': True}
stKeys = set(newDict)
stA = frozenset('a')
stB = frozenset('b')
stC = frozenset('c')
stD = frozenset('d')
print(stKeys)
print(newDict.get(stA & stKeys))
print(newDict.get(stB & stKeys))
print(newDict.get(stC & stKeys))
print(newDict.get(stD & stKeys))
Produce:
>>>None
>>>None
>>>None
>>>None
And even:
print(newDict.get(stA))
print(newDict.get(stB))
print(newDict.get(stC))
print(newDict.get(stD))
Produce:
>>>None
>>>None
>>>None
>>>None
How to retrieve values from the dictionary if your keys are in frozensets?
Thanks to Martijn Pieters! The answer is DVO (Dictionary view objects) and the generator expression if you want to add the result to a list()