In Module 5- More Types , Dictionaries Questions there`s a question that | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

In Module 5- More Types , Dictionaries Questions there`s a question that

Which of the following can`t be used as dictionary key? answer is {2:4,3:9,4:16,} but immediately in next Dictionary Functions their is an example which indicates the same..dictionary declared as squares = {1: 1, 2: 4, 3: "error", 4: 16,} squares[8] = 64 squares[3] = 9 print(squares) Output is given as {1:1,2:4,3:9,4:16} can anyone explain this?

6th Jun 2020, 10:39 AM
Yukti Solanki
Yukti Solanki - avatar
2 Answers
+ 1
The question asked if you could do like this: {{2: 4, 3: 9, 4:16}: "some value"} Where a dictionary was used as a key for another dictionary. You can't.
6th Jun 2020, 10:45 AM
Seb TheS
Seb TheS - avatar
0
You can find the answer on the previous page to that question on the first line. A dictionary key must be immutable whereas dictionary is mutable so you cannot use that as a key.
6th Jun 2020, 10:45 AM
Avinesh
Avinesh - avatar