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?
2 Respuestas
+ 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.
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.