I have a empty dictionary
d = {}
I have these variables:
key = "foo"
value = 1
I want to add them to dictionary as key
and value
variables because they can be change in a for loop. What should be the proper syntax?
I have a empty dictionary
d = {}
I have these variables:
key = "foo"
value = 1
I want to add them to dictionary as key
and value
variables because they can be change in a for loop. What should be the proper syntax?
This is short answer:
d[key] = value
print(d) # d = {"foo" : 1}
see this link for more info about Python dictionary: