I would like to know how could I get the total value of the first quadrant:
aa = { (0, 1) : 4, (2, 2) : 6, (3, 1) : 7, (1, 2) : 10, (3, 2) : 11,(0, -5) : 4, (-2, -2) : 6, (-3, 1) : 7, (1, -2) : 10, (-3, 2) : 11 }
values = aa.values()
total = sum(values)
for (x,y) in aa:
if (x>0 & y>0):
print(total)
else :
pass
You can use the sum
method with a conditional on the x and y coordinates.
aa = {(0, 1): 4, (2, 2): 6, (3, 1): 7, (1, 2): 10, (3, 2): 11, (0, -5): 4, (-2, -2): 6, (-3, 1): 7, (1, -2): 10,
(-3, 2): 11}
total = sum(aa[(x,y)] for x,y in aa if x >= 0 and y >= 0)
print(total) # prints 38