+ 4
Dictionary functions
The result of this code is 8, why ? fib = {1: 1, 2: 1, 3: 2, 4: 3} print(fib.get(4, 0) + fib.get(7, 5))
2 Respuestas
+ 6
general syntax :
dict={key : value,.....}
a=dict.get(key, default=None)
b=dict.get(anotherkey, a value)
#### if the key provided in get method is available in dict...its ok...if not that will add a new key with the passed value(default value is None)
fib = {1: 1, 2: 1, 3: 2, 4: 3}
print(fib.get(4, 0) + fib.get(7, 5))
>>>>>>
fib.get(4, 0) =3
fib.get(7, 5)=5...as 7 isnt a key...it will add the key as 7 with value as 5...
now fib ={ 1: 1, 2: 1, 3: 2, 4: 3, 7:5}
+ 2
thank you so much sayan chandra!! :D