+ 3
why 17 ?
primes = {1: 2, 2: 3, 4: 7, 7:17} print(primes[primes[4]]) why that give to me in output 17 ?
5 ответов
+ 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
+ 7
Primes[4] = 7
Primes[7] = 17
So primes[primes[4]] = primes [7] = 17.
+ 2
primes[4] is 7
primes[7] is 17
+ 2
Arsenic, I didn’t really understand what you wrote, set the process, please.
+ 1
thank you Arsenic, i understand better now