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
Use a dict for grouping:
d = {} for k, v in a_list: d[k] = d.get(k, 0) + v print([[k, d[k]] for k in b_list])
prints:
[['2', 1], ['1', 3]]