list - Python - summing numbers that is the same -


a = [2,2,2,3,4,5,5,6,6,6,7,7] b = [1,2,3,4,5,6,7,8,9,10,11,12] 

i want sum numbers in 'b' in 'a' same , remove duplicated numbers in 'a', output should like:

a = [2,3,4,5,6,7] b = [6,4,5,13,27,23] 

use list comprehension, zipping 2 lists together:

sums = [sum(y x, y in zip(a, b) if x == i) in [j[0] j in groupby(a)]] 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -