当然这可以写得更好,但你应该明白。只需遍历dict,并根据可以动态定义或生成的各种条件检查键的y值。
thing = {
(1,2): 'a',
(2,19): 'b'
}
d1 = {}
d2 = {}
for k, v in thing.items():
// while iterating through the original dict, write some logic to determine how you want to split up based on the y values.
if k[1] < 5:
d1[k] = v
if k[1] < 10:
d2[k] = v
print(d1, d2)