why 17 ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

why 17 ?

primes = {1: 2, 2: 3, 4: 7, 7:17} print(primes[primes[4]]) why that give to me in output 17 ?

3rd Jul 2020, 12:08 AM
Merveille Mitch
Merveille Mitch - avatar
5 Answers
+ 3
Mitch I think you did not know the concept of python dictionaries. It is collection of unordered items which can be accessed using their keys. It's syntax looks like this :- Name = {key:value , key:value} When you write primes[4] it means you want to access element with key 4 which is third element of the dictionary (i.e. 7) Similarly primes[7] is the last element's key. Thus the result is 17. To learn more about dictionary go here👇 https://www.w3schools.com/python/python_dictionaries.asp
3rd Jul 2020, 3:05 AM
Arsenic
Arsenic - avatar
+ 7
Primes[4] = 7 Primes[7] = 17 So primes[primes[4]] = primes [7] = 17.
3rd Jul 2020, 12:31 AM
Arsenic
Arsenic - avatar
+ 2
primes[4] is 7 primes[7] is 17
3rd Jul 2020, 12:31 AM
Gordon
Gordon - avatar
+ 2
Arsenic, I didn’t really understand what you wrote, set the process, please.
3rd Jul 2020, 12:57 AM
Merveille Mitch
Merveille Mitch - avatar
+ 1
thank you Arsenic, i understand better now
3rd Jul 2020, 5:17 PM
Merveille Mitch
Merveille Mitch - avatar