Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python – manipulation of nested lists

let’s say I have a 3 nested lists. I would like to create a new nested lists so that the first nested list will contain first values from the prevoius 3 nested lists, the second nested list will contain second values from previous nested lists and so on. The example:

dd = [[5,8,3],[1,4,2],[1,2,3]]

dd = [[5,1,1],[8,4,2],[3,2,3]]

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can do this with zip,

In [1]: dd = [[5,8,3],[1,4,2],[1,2,3]]

In [2]: list(zip(*dd))
Out[2]: [(5, 1, 1), (8, 4, 2), (3, 2, 3)]

For a list of lists,

In [3]: list(map(list, zip(*dd)))
Out[3]: [[5, 1, 1], [8, 4, 2], [3, 2, 3]]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading