Python error with flattening list of lists
<p>Hi I'm trying to flatten the following list of lists but I always get the following error:</p>

<p>'int' object is not iterable </p>

<p>I also tried chain from itertools but still not working. I guess the solution is easy but I really cannot see it! Anybody can help?</p>

<p>Thanks</p>

<pre><code> from itertools import chain

import operator

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

listone = lista[0][0],[-x[0] for x in lista[:2]]

#sumlistone = chain.from_iterable(listone)

sumlistone = [x for sublist in listone for x in sublist]

print listone

print sumlistone
</code></pre>

<p>Is this what you need?</p>

<pre><code>lista = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]
listb = []

for sub in lista:
    listb.extend(sub)    # Modification suggested by @Dinesh Pundkar 

print(listb)
print(sum(listb))
</code></pre>

python list flatten