1a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
2for key, value in a_dict.items():
3 print(key, '->', value)
1dictionary = {52:"E",126:"A",134:"B",188:"C",189:"D"}
2for key, value in dictionary.items():
3 print(key)
4 print(value)
1#iterate the dict by keys
2for key in a_dict:
3 print(key)
4#iterate the dict by items - (key,value)
5for item in a_dict.items():
6 print(item)
7#iterate the dict by values
8for value in a_dict.values():
9 print(value)
1a_dict = {"color": "blue", "fruit": "apple", "pet": "dog"}
2
3# Will loop through the dict's elements (key, value) WITHOUT ORDER
4for key, value in a_dict.items():
5 print(key, '->', value)
1>>> objects = ['blue', 'apple', 'dog']
2>>> categories = ['color', 'fruit', 'pet']
3>>> a_dict = {key: value for key, value in zip(categories, objects)}
4>>> a_dict
5{'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
6