I have a list of lists that looks like:
[[\'chr1\', \'3088\', \'1\', 744, \'L1MCc_dup1\'] [\'chr1\', \'3089\', \'1\', 744, \'L1MCc_dup1\'] [\'chr1\', \'3090\', \
Use a dictionary:
d = {} for row in my_list: key = row[4] value = int(row[2]) d[key] = d.get(key, 0) + value
After this loop, d will map the key values in the last column to the desired sums.
d
You could also use collections.defaultdict instead of a normal dictionary.
collections.defaultdict