Answers for "iterate through array and dictionary"

37

python iterate through dictionary

a_dict = {'apple':'red', 'grass':'green', 'sky':'blue'}
for key in a_dict:
  print key # for the keys
  print a_dict[key] # for the values
Posted by: Guest on November-12-2019
0

python iterate through keys in dictionary

a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
keys = a_dict.keys()
keys

#prints:
#dict_keys(['color', 'fruit', 'pet'])
Posted by: Guest on June-25-2021

Code answers related to "iterate through array and dictionary"

Python Answers by Framework

Browse Popular Code Answers by Language