This is a blog about Python Programming. It draws inspiration from Zen practices such as simplicity and unclutteredness. Your comments and suggestions to improve the posts will be greatly appreciated.
Friday, April 1, 2016
Quick Reference: How to iterate over keys and values at once on a Python 3 dictionary
On Python 3, we use the items() method to iterate over a dictionary's keys and values simultaneously.
dictionary = {"name": "John", "age": "32"}
for key, val in dictionary.items():
print(key, val)
When the above code is executed, it produces the following result:
No comments:
Post a Comment