How do I print the key-value pairs of a dictionary in python
You can use the items() method to print the key-value pairs of a dictionary in Python.
You can use the items() method to print the key-value pairs of a dictionary in Python. Here's an example code snippet:
Print the key-value pairs of a dictionary in Python
python— editable, runs on the server
This will output:
key-value pair output
a 1
b 2
c 3You can also use the for loop to iterate over the keys of the dictionary and then use the key to access the corresponding value. Here's an example code snippet:
Iterate over the keys of the dictionary in Python
python— editable, runs on the server
This will also give the same output as the previous example
iteration output
a 1
b 2
c 3