Dictionary comprehensive notation

1


name = ['Taro', 'Jiro', 'Saburo']
job = ['Brave', 'Warrior', 'Wizard']
d= {}

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

print(d)

Execution result of 1


{'Taro': 'Brave', 'Jiro': 'Warrior', 'Saburo': 'Wizard'}

If you write this in dictionary comprehensive notation

Dictionary comprehensive notation


name = ['Taro', 'Jiro', 'Saburo']
job = ['Brave', 'Warrior', 'Wizard']

d = {x: y for x, y in zip(name, job)}
print(d)

Execution result of dictionary comprehensive notation


{'Taro': 'Brave', 'Jiro': 'Warrior', 'Saburo': 'Wizard'}

Recommended Posts

Dictionary comprehensive notation
Comprehension notation
Python -I tried to restore the dictionary comprehensive notation to its original form-
Format notation
Dictionary type 2
Dictionary type 1
[Python] dictionary
Python dictionary
Comprehension notation