I started with 2 different ways to make a key-value-reversed dictionary from a known dictionary. When I try to figure out whether these 2 are identical, I got this question. Here is my code.
a = {'a': 1, 'b': 2, 'c': 3} # known dict
b = dict([(v, k) for k, v in a.items()]) # way # 1 to reverse
c = {v: k for k, v in a.items()} # way # 2 to reverse
print(b.values()) # returns dict_values(['a', 'b', 'c'])
print(c.values()) # returns dict_values(['a', 'b', 'c'])
print(b.values() == c.values()) # returns False
print(b.keys()) # returns dict_keys([1, 2, 3])
print(c.keys()) # returns dict_keys([1, 2, 3])
print(b.keys() == c.keys()) # returns True
print(b == c) # returns True
I know that both dict.values() and dict.keys() returns a dictionary_view. What is this dictionary_view? Why b.values() and c.values() seem to be identical while they are not but b.keys() equal to c.keys()?
I also tries this code.
import types
print(isinstance(b.values(), types.GeneratorType))
And it returns False.