Transpose list of lists

0 votes
I have the following code :

l = [[1,2,3],[4,5,6],[7,8,9]]

The result I'm looking for is

r = [[1,4,7],[2,5,8],[3,6,9]]

and not

r = [(1,4,7),(2,5,8),(3,6,9)]

Can anyone help me how to get that?
Mar 1 in Python by ana1504.k
• 6,110 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
You can try the following and see if it works :

map(list, zip(*l))
--> [[1, 4, 7], [2, 5, 8], [3, 6, 9]]

For python 3.x users can use :

list(map(list, zip(*l)))
answered Mar 1 by SDeb
• 9,660 points

Related Questions In Python

0 votes
1 answer

Python: list of lists

Lists are a mutable type - in ...READ MORE

answered Aug 2, 2018 in Python by bug_seeker
• 14,970 points
+2 votes
2 answers

In a list of dictionaries, how can I find the minimum calue in a common dictionary field.

There are several options. Here is a ...READ MORE

answered Apr 10, 2018 in Python by charlie_brown
• 7,710 points
+1 vote
4 answers

Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

answered Oct 18, 2018 in Python by tinitales
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
0 votes
1 answer

Python: Sort list of lists numerically

You can try and De-dupe it with ...READ MORE

answered 3 days ago in Python by SDeb
• 9,660 points
0 votes
1 answer

Return a list inside a for loop while iterating over the elements of another list

The print() is getting called multiple times ...READ MORE

answered Sep 21, 2018 in Python by SDeb
• 9,660 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.