How to zip with a list output in Python instead of a tuple output?

0 votes
Hi all, pretty simple question. My requirement is that I want to know which is the most efficient way of obtaining a list of lists from a set of lists. Let us say I want a list from a set of 2 lists.

How do I go about doing this?

Check out the following input:

And this is what I would want:

Can we make use of maps instead of zip to achieve this? The problem is that I am unaware of any of the standard libraries that are present to suit my requirement.

I am aware that I can define my own function and make use of it as well.

All help appreciated!
Feb 7 in Python by Anirudh
• 2,060 points

1 answer to this question.

0 votes

Good question - Considering that you are actually zipping more than two lists, you can make use of the following syntax:

[list(a) for a in zip([1,2,3], [4,5,6], [7,8,9])]

What this basically does is that this makes use of the comprehensions of the list and ends up converting each of the element present in the tuple into lists as per your requirement.

Hope this helps!

answered Feb 7 by Nymeria
• 3,500 points

Related Questions In Python

0 votes
1 answer

How to get permutations of list or a set in Python?

Permutation is an arrangement of objects in ...READ MORE

answered 5 days ago in Python by Neel
• 1,470 points
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
2 answers

How to calculate square root of a number in python?

calculate square root in python >>> import math ...READ MORE

answered Apr 2 in Python by anonymous
0 votes
1 answer

How to print first character of each word in upper case of a string in Python

You can use split() using space as ...READ MORE

answered Jun 1, 2018 in Python by george
• 200 points
+1 vote
2 answers

how can i count the items in a list?

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

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 124 views
+4 votes
6 answers
0 votes
1 answer

List comprehension on a nested list - How to do it in Python?

Not sure what your desired output is, ...READ MORE

answered Nov 21, 2018 in Python by Nymeria
• 3,500 points