1

Assume you have a list :

mylist=[[1,2,3,4],[2,3,4,5],[3,4,5,6]]

any pythonic(2.x) way to unpack the inner lists so that new list should look like ?:

mylist_n=[1,2,3,4,2,3,4,5,3,4,5,6]
Krcn U
  • 411
  • 1
  • 9
  • 16

2 Answers2

6
import itertools
mylist=[[1,2,3,4],[2,3,4,5],[3,4,5,6]]
print list(itertools.chain(*mylist))
Cody Bouche
  • 945
  • 5
  • 10
6
mylist_n = [j for i in mylist for j in i]
John La Rooy
  • 295,403
  • 53
  • 369
  • 502
  • Would you mind explaining the last part "**for j in i**" I do not get it, what does this mean? – AmirWG Aug 08 '22 at 20:38