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,050 points
32 views

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

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 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
415 views
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
100 views
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,020 views
0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

answered Jun 4, 2018 in Python by ariaholic
• 7,320 points
47 views
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
19 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
35 views

© 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.