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, 2019 in Python by Anirudh
• 2,080 points
268 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, 2019 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, 2019 in Python by Neel
• 3,010 points
4,180 views
0 votes
0 answers
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, 2019 in Python by Arvind
• 2,980 points
296 views
0 votes
1 answer

How to create a zip archive of a directory in Python?

Hello @kartik, The easiest way is to use shutil.make_archive. ...READ MORE

answered May 11 in Python by Niroj
• 67,860 points
61 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, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,472 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,800 points
1,103 views
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
558 views