0
primes={1:2,2:3,4:5,6:11} print (primes [primes [4]]
What is the output? And how? Explain plZ
9 Answers
+ 5
Mhr Habib Great, you already have half or your answer by yourself. And Jomari explained why
+ 2
Why don't you try it yourself?!
0
Its giving me a key error in the playground but in the lecture its gives output of 11
0
This would result in an error.
primes[4] resolves to 5, while primes[5] is missing.
Basically, what happens here is that the `thing` inside the bracket is the KEY for the dictionary to get its value.
primes[4] is 5 because you declared 4:5. primes[5] on the other hand is not present.
0
Jomari pantorilla have you seen the dictionary functon first question
0
@Mhr Habib What do you mean by if I "saw the dictionary function"?
Have you checked again if maybe you've made a typo? If 6:11 becomes 5:11 instead, then the expected output of 11 would be correct.
0
If it is indexing... Then my thinking is correct ...output is 11 ..
0
Oh. Maybe you're mixing up arrays and dicts?
0
Mhr Habib Dictionaries are unordered and don't support indexing. If you could use indices, you couldn't tell if primes[1] referred to the value with the key 1 (2) or the second value (3).
Since the prime number 7 is missing, I also think that the dictionary in your question is incomplete.