Python Forum
Newbie question for unzip zipped list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie question for unzip zipped list
#1
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,
Reply
#2
a, b, c, d = zip(*zip4List)
That will get you tuples, but if you really need lists, you can call list() on them.
Reply
#3
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)]
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How is pandas modifying all rows in an assignment - python-newbie question markm74 1 690 Nov-28-2023, 10:36 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 675 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Newbie question about switching between files - Python/Pycharm Busby222 3 592 Oct-15-2023, 03:16 PM
Last Post: deanhystad
  Newbie.... run for cover. OpenCV question Stevolution2023 2 960 Apr-12-2023, 12:57 PM
Last Post: Stevolution2023
  numpy newbie question bcwilly_ca 4 1,172 Feb-10-2023, 05:55 PM
Last Post: jefsummers
  Question from complete python's newbie Davicom 3 2,357 Jun-09-2021, 06:09 PM
Last Post: bowlofred
  Newbie question about running Python via GUI on OSX ejwjohn 8 3,495 Feb-05-2021, 03:20 PM
Last Post: Larz60+
  super newbie question: escape character tsavoSG 3 2,427 Jan-13-2021, 04:31 AM
Last Post: tsavoSG
  newbie question....importing a created class ridgerunnersjw 5 2,623 Oct-01-2020, 07:59 PM
Last Post: ridgerunnersjw
  Dumb newbie question JonEdward 5 3,223 Jul-22-2020, 10:06 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020