What is the output of the following Python code snippet?
d = {'a': 1, 'b': 2}
print({k: v for k, v in d.items() if v
Correct answer
A. {'a': 1}
5 views
A. {'a': 1}
5 views
Dict comprehension with a filter keeps only items satisfying the condition.
Asked in: Python Interview Dictionaries
https://docs.python.org/3/tutorial/datastructures.html#dictionariesNot sure why the answer is A? Ask here and get an explanation.