12
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pythonでzip、unzip

Posted at

といっても、.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)]
12
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?