Dictionaries
Dictionaries in Python
# Define dict:
dict = {
'k1': 'some data',
7: ['can', 'be', 'a', 'list']
}
# Dictionaries are not position oriented, they are key oriented
# To get the data:
dict['k1'] # prints 'some data'
print(dict[7]) # prints ['can', 'be', 'a', 'list']dict[7] = 'new value'people_weight_dict = {
'john': 123,
'mike': 170,
'robert': 167
}
# To change john's weight you would do
people_weight_dict['john'] = 134Clear method
Adding items to dictionary:
Last updated