Answers for "python iterate over keys in dicts"

16

python loop through dictionary

new_list = [something(key, value) for key, value in a_dict.items()]
Posted by: Guest on April-23-2020
6

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
Posted by: Guest on May-05-2020

Code answers related to "python iterate over keys in dicts"

Python Answers by Framework

Browse Popular Code Answers by Language