iterate through dictionary

Do you want to know the details regarding “iterate through dictionary”. If yes, you’re in the correct tutorial.

iterate through dictionary

a_dict = 'color': 'blue', 'fruit': 'apple', 'pet': 'dog'
for key, value in a_dict.items():
  print(key, '->', value)
dictionary = 52:"E",126:"A",134:"B",188:"C",189:"D"
for key, value in dictionary.items():
	print(key)
	print(value)
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
new_list = [something(key, value) for key, value in a_dict.items()]
a_dict = "color": "blue", "fruit": "apple", "pet": "dog"

# Will loop through the dict's elements (key, value) WITHOUT ORDER
for key, value in a_dict.items():
  print(key, '->', value)
d = 'x': 1, 'y': 2, 'z': 3 
for key in d:
    print key, 'corresponds to', d[key]

Conclusion

I hope this post helps you to know about “iterate through dictionary”. If you have any doubts regarding this article please let us know via the comment section. Share this tutorial with your friends & family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment