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,070 points
41 views

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,520 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 Jul 11 in Python by Neel
• 2,690 points
30 views
0 votes
1 answer

How to get a list of built in modules in Python?

simply open the python shell and type ...READ MORE

answered Aug 1 in Python by Arvind
• 2,680 points
25 views
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
617 views
+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 173 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,520 points
77 views