Create dictionary where keys are from a list and values are the sum of corresponding elements in another list
<p>I have two lists L1 and L2. Each unique element in L1 is a key which has a value in the second list L2. I want to create a dictionary where the values are the sum of elements in L2 that are associated to the same key in L1.</p>

<p>I did the following but I am not very proud of this code. Is there any simpler pythonic way to do it ?</p>

<pre><code>L = [2, 3, 7, 3, 4, 5, 2, 7, 7, 8, 9, 4] # as L1
W = range(len(L)) # as L2

d = { l:[] for l in L }
for l,w in zip(L,W): d[l].append(w)
d = {l:sum(v) for l,v in d.items()}
</code></pre>

<p><strong>EDIT:</strong></p>

<p><strong>Q:</strong> How do I know which elements of L2 are associated to a given key element of L1?</p>

<p><strong>A:</strong> if they have the same index. For example if the element 7 is repeated 3 times in L1 (e.g. L1[2] == L1[7] == L1[8] = 7), then I want the value of the key 7 to be L2[2]+L2[7]+L2[8] </p>