0
Dictionary Question
X = {1:2, 2:3, 3:4, 4:6} print(x.get(2, 0)%x.get(5, 4)) Solution: 3 So lost:(. It's a dictionary, but there is no key 5, so what're they looking for? Can't get any sums to give me %=3 either. Any ideas (any help appreciated:)).
2 odpowiedzi
+ 5
get returns the second argument, if it doesn't find the key.
So if 2 wasn't in X, the first return value would be 0; since 5 isn't in the dictionary, the second return value will be 4.
So it's 3%4 what's happening there.
+ 2
The method get(key, default_value = None) returns a value for the given key. If key is not available then returns default_value.
So get(5, 4) == 4 and 3%4 == 3.
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2451/