0
Pls help me with the logic
x={1:2,2:3,3:4,4:6} print(x.get(2,0)%x.get(5,4))
4 Answers
+ 11
x.get(a, b) tries to get the value of the key a in the dictionary x. If the key is not found, it returns b. So
x.get(2, 0) = x[2] = 3, as 2 is a key in x.
x.get(5, 4) = 4, as 5 is not a key in x.
3 % 4 = 3, the result.
Get is a safer method than using x[a], which throws KeyError if the key is not present. You can read more about get() here on the third tab:
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2451/?ref=app
+ 6
Gordon me, toođ
Thanks Kishalaya Saha đ
+ 5
Gordon Glad to hear that đ
+ 2
Oh I didn't know this, learned something new đ