How would you loop over every key and value in a python dictionary?

The method depends on which python version you are using.For python 2.xfor key, value in d.iteritems() ... For python 3.xfor key, value in d.items() ... In both examples key, and value are just variable names and can be changed for any string.

KN

Related Python Mentoring answers

All answers ▸

What would output this code? print(hello world)


Write a program that computes the sum of all numbers up to a input number n


How do I use for loops in Python?


What's the difference between a local and a global variable?