LoginSignup
1
2

More than 5 years have passed since last update.

pythonでunzipする

Posted at

pythonのzip関数の逆のものがないかなと思ってググったら出てきました

python - How to unzip a list of tuples into individual lists? - Stack Overflow

in Python 2.xみたいな話題も出てましたが、手元のpython3.5.2rcでも動きました

>>> li = [('a', 12), ('b', 23), ('c', 34)]
>>> for e in zip(*li): e
...
('a', 'b', 'c')
(12, 23, 34)

関数にするとこんな感じですかね

def unzip(li):
    return map(list, zip(*li))
1
2
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
1
2