1
0

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 1 year has passed since last update.

zip関数で複数のリストをまとめて操作

Posted at

zip関数は複数のリストを要素ごとにまとめて取得する関数
リストは三つ以上でも可能

suit = ['spade', 'heart', 'diamond','club']
number = [12, 1, 5]

for suit, number in zip(suit, number):
    print(suit, number)
# spade 12
# heart 1
# diamond 5

足りなかった片方は無視される


forを使わなくてもzip関数は使うことができる

suit = ['spade', 'heart', 'diamond','club']
number = [12, 1, 5,7]

Playing_Card_List = list(zip(suit, number))

print(Playing_Card_List)

# [('spade', 12), ('heart', 1), ('diamond', 5), ('club', 7)] 

今回の学びはzip関数と英語でトランプのマークをsuitと呼ぶことだ
ちなみにトランプというのは日本人だけで、その由来は海外の人が切り札という意味でトランプと言ったことをカードのことを意味していると勘違いした人がいたことかららしい(諸説あり)

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?