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 can I do with Python?


Make a program that asks the user for a series of numbers until they either want to output the average or quit the program.


Write a basic program to output the lowest of 3 input numbers. (You may omit error checks on your inputs)


How do I define a function in Python?