What is the output of the following Python code snippet?
d = {'a': 2, 'b': 1}
print({v: k for k, v in d.items()})
print({v: k for k, v in d.items()})
Correct answer
D. {2: 'a', 1: 'b'}
6 views
D. {2: 'a', 1: 'b'}
6 views
Inverting a dictionary returns keys as values.
Asked in: Python Interview Advanced
https://docs.python.org/3/library/index.htmlNot sure why the answer is D? Ask here and get an explanation.