Newbie question for unzip zipped list - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Newbie question for unzip zipped list (/thread-6965.html) |
Newbie question for unzip zipped list - zydjohn - Dec-15-2017 Hello: I have some code, but I want to do the reverse: list1 = [1,2,3,4] list2 = [2,3,4,5] list3 = [3,4,5,6] list4 = [4,5,6,7] zip4List = zip(list1,list2,list3,list4)The fact is: I already have a zipped list which was generated by 4 lists zipped together, but I want to get each of the list from the zipped one, in my above example, I want to get the list1, list2, list3 and list4. I search around, it seems python has only zip function, but no unzip function. Any idea how to code to unzip the above zipped list? Thanks, RE: Newbie question for unzip zipped list - stranac - Dec-15-2017 a, b, c, d = zip(*zip4List)That will get you tuples, but if you really need lists, you can call list() on them.
RE: Newbie question for unzip zipped list - wavic - Dec-15-2017 What does zipped list mean? zip(*args) returns a zip object which is either iterator or generator. Don't know exactly. So, zip4list is not a list of lists. In order to get one is a little change. zip4list = [list(item) for item in zip(list1,list2,list3,list4)] |