Python Dictionary 3

0

Hello, could anyone help me understand why 8 is the correct answer? Thank you in advance.

    
asked by anonymous 26.12.2017 / 14:24

1 answer

3

The get (key, default) function returns the value on the map according to the specific key key .

On the map we have the following keys: 1, 2, 3, 4 , with the following values: 1, 1, 2, 3

In the example:

fib.get(4, 0)

You will recover the value that has the 4 key, in this case, the value 3 . If it did not exist in the key map with this value would be returned 0 .

fib.get(7, 5)

You will get the value that has the 7 key, as it has no value in the map with this key will be returned the default value 5

As a result then we have 3 + 5 = 8

A didactic reference: link

    
26.12.2017 / 15:05