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))

15th Nov 2018, 8:42 AM
AMAN TOMAR
AMAN TOMAR - avatar
4 Antworten
+ 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
15th Nov 2018, 8:49 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 6
Gordon me, too😂 Thanks Kishalaya Saha 😆
16th Nov 2018, 10:58 AM
Flandre Scarlet
Flandre Scarlet - avatar
+ 5
Gordon Glad to hear that 😊
16th Nov 2018, 10:22 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
Oh I didn't know this, learned something new 😂
16th Nov 2018, 10:21 AM
Gordon
Gordon - avatar