Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Newbie question for unzip zipped list
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?
a, b, c, d = zip(*zip4List)
That will get you tuples, but if you really need lists, you can call list() on them.
zydjohn likes this post
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."

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Dumb newbie question JonEdward 5 369 Jul-22-2020, 10:06 PM
Last Post: snippsat
  Multiple lambda functions in zipped list not executing psolar 0 253 Feb-13-2020, 12:53 PM
Last Post: psolar
  Newbie Question juljan 4 477 Jan-13-2020, 03:07 AM
Last Post: snippsat
  Newbie question... mrochac 2 343 Nov-14-2019, 02:55 PM
Last Post: Larz60+
  Newbie question Shadowlord 2 401 Sep-30-2019, 12:52 PM
Last Post: Shadowlord
  Definition of .format? (Newbie question) Jan_97 4 650 Jul-13-2019, 12:49 PM
Last Post: Jan_97
  Newbie Question re "TypeError: '<' not supported between instances of 'list' and 'int sr12 8 3,071 Apr-11-2019, 08:19 PM
Last Post: sr12
  about List question longmail 2 764 Nov-30-2018, 02:08 AM
Last Post: longmail
  [newbie] question on what to put in () on target.write MattSS102 5 2,348 Feb-22-2018, 06:54 PM
Last Post: Dixon
  Learning Python, newbie question about strings and evaluation new_learner_999 13 2,172 Feb-18-2018, 03:01 PM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)