I have a list and a set:
a_list = [[\'1\', 2], [\'2\', 1], [\'1\', 1]]
b_list = {\'1\', \'2\'}
I\'m looking to correspond the items in b_list
This returns sums only for items defined in find.
items = [['1', 2], ['2', 1], ['1', 1], ['3',1]]
find = {'1', '2'}
results = {}
for item in items:
key = item[0]
value = item[1]
if key in find:
results[key] = results.get(key,0) + value
[[key, value] for key, value in results.items()]
Outputs [['2', 1], ['1', 3]]