-4

how can I create a new list with the following format.

The 3 arrays inside each row should be in different rows.

a= [['111,0.0,1', '111,1.27,2', '111,3.47,3'],
    ['222,0.0,1', '222,1.27,2', '222,3.47,3'],
    ['33,0.0,1', '33,1.27,2', '33,3.47,3'],
    ['44,0.0,1', '44,1.27,2', '4,3.47,3'],
    ['55,0.0,1', '55,1.27,2', '55,3.47,3']]

Final desired ouput:

 b=[['111,0.0,1', 
  '111,1.27,2', 
  '111,3.47,3',
  '222,0.0,1', 
  '222,1.27,2', 
  '222,3.47,3',
  '33,0.0,1', 
  '33,1.27,2', 
  '33,3.47,3',
  '44,0.0,1',
  '44,1.27,2',
  '44,3.47,3',
  '55,0.0,1', 
  '55,1.27,2', 
  '55,3.47,3']]
lolo
  • 646
  • 2
  • 7
  • 19

2 Answers2

1

Is this what you are looking for?

b = [[j for i in a for j in i]]
Fariborz Ghavamian
  • 809
  • 2
  • 11
  • 23
1

To be clear, there is no concept of rows vs. columns in Python. Your end result is just a big list of str's, within another list.

You can create the big list by chaining all of the original small lists together (a[0] + a[1] + ...), for which we may use

import itertools
big_list = list(itertools.chain(*a))

To put this inside another list,

b = [big_list]
jmd_dk
  • 12,125
  • 9
  • 63
  • 94