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
Accumulate numbers using a dict, and then gather the results using a list comprehension:
>>> d = dict.fromkeys(b_list, 0) >>> for k, n in a_list: ... if k in d: ... d[k] += n ... >>> [[k, n] for k, n in d.items()] [['1', 3], ['2', 1]]