0
Output Working
fib = {1: 1, 2: 1, 3: 2, 4: 3} print(fib.get(4, 0) + fib.get(7, 5)) How it's working?
2 Answers
+ 3
the get(a,b) returns fib[a] if a exists as key, else b.
+ 1
the dictionary get method has two parameters : the first is the key of the element and the second one is the default value which will be returned if the dictionary does not have such key.
so fib.get(4,0)+fib.get(7,5) = 3 +5 =8
because the 7 is not a key of fib.