Which Choice Cannot be Used as an Entry? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Which Choice Cannot be Used as an Entry?

False 0 {2: 4, 3: 9, 4: 16,} <----- this apparently cannot be used as a dict entry. But running >>>squares = {2: 4, 3: 9, 4: 16,} print(squares) Runs just fine. I'm having issues understanding a lot of this "simple" stuff :( How come the question says that's wrong, but Python's like "it's okay."?

31st Mar 2017, 9:15 PM
James Bradley
James Bradley - avatar
4 Answers
+ 6
The question in the course is, whether or not you can use this as a key, not if that is a valid dictionary. {{2: 4, 3: 9, 4: 16,}: "Brian"} should not work.
31st Mar 2017, 9:36 PM
Tob
Tob - avatar
+ 6
@ James: Let's be precise here. The Key:Value pair is part of a larger object, namely a dictionary. And you cannot use dictionaries as keys in other dictionaries.
31st Mar 2017, 10:26 PM
Tob
Tob - avatar
+ 2
@ Tobi: Oh okay that makes sense. After defining a Key:Value you cannot use that as a Key itself to define another value... right? It's taking me way longer than I'd appreciate to understand this stuff, lol.
31st Mar 2017, 9:51 PM
James Bradley
James Bradley - avatar
+ 1
gotcha. i thought it was referring to using that Key:Value set in 1 dictionary alone. thanks for your time, and responses :) You're the Man Now, Dawg.
31st Mar 2017, 11:15 PM
James Bradley
James Bradley - avatar