num_list = [[5, 1], [10, 1], [30, 2], [20, 2]]
sum_list1 = [15, 1]
sum_list2 = [50, 2]
for e in set([l[-1] for l in num_list]):
print([e, sum([l[0] for l in num_list if l[1] == e])])
def get_iter(num_list):
for e in set([l[-1] for l in num_list]):
yield [sum([l[0] for l in num_list if l[1] == e]), e]
for e in get_iter(num_list):
print(e)