CBSE Class 12 Computer Science
Question 93 of 105
Python Revision Tour II — Question 20
Back to all questions30
{(1, 2, 4): 8, (4, 2, 1): 10, (1, 2): 12}
- An empty dictionary named
my_dictis initialized. my_dict[(1,2,4)] = 8, my_dict[(4,2,1)] = 10, my_dict[(1,2)] = 12these lines assign values to the dictionarymy_dictwith keys as tuples. Since tuples are immutable, so they can be used as keys in the dictionary.- The
forloop iterates over the keys of the dictionarymy_dict. Inside the loop, the value associated with each key k is added to the variablesum. sumandmy_dictare printed.