python keys of dict code example
Example 1: for key value in dict python
a_dict = {"color": "blue", "fruit": "apple", "pet": "dog"}
for key in a_dict:
print(key, '->', a_dict[key])
# Output:
# color -> blue
# fruit -> apple
# pet -> dog
Example 2: python convert dict_keys to list
d = {1:1, 2:2, 3:3}
d_keys_list = list(d.keys())
Example 3: dict keys
# To get all the keys of a dictionary use 'keys()'