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, 2019 in Python 1,045 views

## 1 answer to this question.

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)))
• 13,300 points

## Python: list of lists

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

## How to make a flat list out of list of lists?

Hii @kartik, Given a list of lists l, flat_list = ...READ MORE

## How to unzip a list of tuples into individual lists?

Hello @kartik, zip is its own inverse! Provided you ...READ MORE

## How to make a flat list out of list of lists?

Hello @kartik, You can use itertools.chain(): import itertools list2d = [[1,2,3], ...READ MORE

## how do i change string to a list?

suppose you have a string with a ...READ MORE

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE