+ 1

Can someone explain me last question (dictionary function)

2nd May 2017, 9:03 AM
Yusuf Andi Saputro
Yusuf Andi Saputro - avatar
6 Answers
+ 2
Do you mind posting the question here? :)
2nd May 2017, 9:14 AM
Thanh Le
Thanh Le - avatar
+ 2
I already explained how dict.get works here: https://www.sololearn.com/Discuss/357763 If you read that answer, you should be able to answer this question on your own. For more questions on that, please use that thread. Answer should be 8 by the way.
2nd May 2017, 11:34 AM
Tob
Tob - avatar
+ 2
8 = 3 (See in dictionary key 4) + 5 (see the default value)
2nd May 2017, 11:38 AM
Thanh Le
Thanh Le - avatar
+ 1
What is the result of this code? fib = {1: 1, 2: 1, 3: 2, 4: 3} print(fib.get(4, 0) + fib.get(7, 5)) ---------------------------------------- Answer: fib.get(4,0) is looking for key 4 in fib, and 4 has a value 3 so: fib.get(4,0) = 3 Next, fib.get(7, 5) is looking for key 7, but there is no such a key. There are only keys from 1 to 4! So because there is no 7 key, it assigns a value 5. And 3 + 5 = 8 print(fib.get(4, 0) + fib.get(7, 5)) 3 + 5
5th May 2017, 6:17 PM
Tommy L
Tommy L - avatar
0
a ={1:1, 2:1, 3:2, 4:3} print(a.get(4,0)+a.get(7,5))
2nd May 2017, 11:13 AM
Yusuf Andi Saputro
Yusuf Andi Saputro - avatar
0
what is default value?
2nd May 2017, 12:21 PM
Yusuf Andi Saputro
Yusuf Andi Saputro - avatar