0

I have n lists with n elements which looks like this, in this example I will show only one with 2 elements, but it could be n:

['-', '-']
['4.500.740', '924.372']
['1.978.095', '3.802.674']
['3.434.599', '3.614.503']
['8.588.294', '4.973.343']

I need to create one single nested list that looks like the next one:

[['-','4.500.740','1.978.095','3.434.599','8.588.294'],['-','924.372','3.802.674','3.614.503','4.973.343']]

I've been looking with many related questions to this, but I can't figure it out yet, so any advice will be appreciated.

Red
  • 26,798
  • 7
  • 36
  • 58
  • 1
    `zip`is what you are looking for – Ch3steR May 24 '20 at 04:09
  • `list(zip(*lists))`? But how are these lists related? Is this a 2d list or are they just floating loose? If it's a 2d list, please add `[]` around it and comma-delimit it so there's no ambiguity. – ggorlen May 24 '20 at 04:09

1 Answers1

1

You can use list comprehensions:

l1 = [['-', '-'],
      ['4.500.740', '924.372']]

l2 = [[a[n] for a in l1] for n in range(len(l1))]

print(l2)
Red
  • 26,798
  • 7
  • 36
  • 58