1
2

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.

zip関数について

Last updated at Posted at 2018-11-27

背景

kaggleのサッカーのデータセットに対してのタプルを作成する方法を模索していた際にzip関数を使用しました。

zip関数について

zip関数は複数のリストを抽出したり、タプルを作成します。

zip.py

a = [1, 2, 3, 4]
b = [2, 4, 6, 8]
c = []
for i in zip(a, b):
    c.append(i)
print(c)

c = [(1,2), (2,3), (3,4)]

以下のように複数のリストのそれぞれの要素の抽出に成功しました!!
また、タプルを作成する場合は、以下のようにします!!
tuple(c) c = ((1, 2), (2, 3), (3, 4))

1
2
4

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?