Question: I have two lists like this,

```
a=[['a', 'b', 'c'], ['b', 'c'], ['a', 'd'], ['x']]
b=[[1, 2, 3], [4,5], [6,7], [8]] (the size of a and b is always same)

```

Now I want to create two list with the sum of unique elements, so the final lists should look like,

```
 a=['a', 'b', 'c', 'd', 'x']
 b=[7, 6, 8, 7, 8] (sum of all a, b, d, d and x)

```

I could do this using for loop but looking for some efficient way to reduce execution time.

Answer: 
Not so pythonic but will do the job:

```
a=[['a', 'b', 'c'], ['b', 'c'], ['a', 'd'], ['x']]
b=[[1, 2, 3], [4,5], [6,7], [8]]

mapn = dict()
for elt1, elt2 in zip(a, b):
    for e1, e2 in zip(elt1, elt2):
        mapn[e1] = mapn.get(e1, 0) + e2

elts = mapn.keys()
counts = mapn.values()

print(mapn)
print(elts)
print(counts)

```
Here some ideas.

First, to flatten your list you can try:

```
a=[['a', 'b', 'c'], ['b', 'c'], ['a', 'd'], ['x']]
b=[[1, 2, 3], [4,5], [6,7], [8]]

```

To have uniques elements, you can do something like

```
A = set([item for sublist in a for item in sublist])

```

But what I would do first (perhaps not the more efficient) is :

```
import pandas as pd
import bumpy as np
LIST1 = [item for sublist in a for item in sublist]
LIST2 = [item for sublist in b for item in sublist]
df = pd.DataFrame({'a':LIST1,'b':LIST2})
df.groupby(df.a).sum()

```

OUTPUT:

[![enter image description here](https://i.stack.imgur.com/8dIkf.png)](https://i.stack.imgur.com/8dIkf.png)