LoginSignup
0
1

More than 3 years have passed since last update.

辞書包括表記

Last updated at Posted at 2020-01-15
1
name = ['太郎', '次郎', '三郎']
job = ['勇者', '戦士', '魔法使い']
d= {}

for x, y in zip(name, job):
    d[x] = y

print(d)
1の実行結果
{'太郎': '勇者', '次郎': '戦士', '三郎': '魔法使い'}

これを辞書包括表記で書くと

辞書包括表記
name = ['太郎', '次郎', '三郎']
job = ['勇者', '戦士', '魔法使い']

d = {x: y for x, y in zip(name, job)}
print(d)
辞書包括表記の実行結果
{'太郎': '勇者', '次郎': '戦士', '三郎': '魔法使い'}
0
1
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
0
1