Help us understand the problem. What is going on with this article?

pythonでzip、unzip

More than 5 years have passed since last update.

といっても、.zipを作るわけじゃない。
listを結合する方のzipのお話。

zip関数の挙動はこんな感じ

>>> list1 = [1,2,3,4]
>>> list2 = [5,6,7,8]
>>> list3 = zip(list1,list2)
>>> list3
[(1, 5), (2, 6), (3, 7), (4, 8)]

で、zipできるならunzipしたいと思うが、pythonにunzip関数はない!
なので、unzipしたい時は可変変数を使うといいらしい。

>>> zip(*list3)
[(1, 2, 3, 4), (5, 6, 7, 8)]
wwacky
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away