René's URL Explorer Experiment


Title: How to Iterate Through a Dictionary in Python – Real Python

Open Graph Title: How to Iterate Through a Dictionary in Python – Real Python

Description: In this tutorial, you'll take a deep dive into how to iterate through a dictionary in Python. Dictionaries are a fundamental data type in Python, and you can solve various programming problems by iterating through them.

Open Graph Description: In this tutorial, you'll take a deep dive into how to iterate through a dictionary in Python. Dictionaries are a fundamental data type in Python, and you can solve various programming problems by iterating through them.

Mail addresses
?subject=Python article for you&body=How to Iterate Through a Dictionary in Python on Real Python https://realpython.com/iterate-through-dictionary-python/

Opengraph URL: https://realpython.com/iterate-through-dictionary-python/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
{
  "@context": "http://schema.org",
  "@type": "Article",
  "headline": "How to Iterate Through a Dictionary in Python",
  "image": {
    "@type": "ImageObject",
    "url": "https://files.realpython.com/media/How-to-Iterate-Through-A-Dictionary-in-Python_Watermarked.06d6547f531b.jpg",
    "width": 1920,
    "height": 1080
  },
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://realpython.com/iterate-through-dictionary-python/",
    "lastReviewed": "2024-11-23",
    "author": {
      "@type": "Person",
      "name": "Leodanis Pozo Ramos",
      "image": "https://realpython.com/cdn-cgi/image/width=862,height=862,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Perfil_final1.9f896bc212f6.jpg",
      "url": "https://realpython.com/team/lpozoramos/",
      "affiliation": {
        "@type": "Organization",
        "@id": "https://realpython.com/#organization",
        "name": "Real Python",
        "url": "https://realpython.com",
        "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
      }
    },
    "reviewedBy": [
      {
        "@type": "Person",
        "name": "Aldren Santos",
        "image": "https://realpython.com/cdn-cgi/image/width=500,height=500,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Aldren_Santos_Real_Python.6b0861d8b841.png",
        "url": "https://realpython.com/team/asantos/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Brenda Weleschuk",
        "image": "https://realpython.com/cdn-cgi/image/width=320,height=320,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/IMG_3324_1.50b309355fc1.jpg",
        "url": "https://realpython.com/team/bweleschuk/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Geir Arne Hjelle",
        "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/gahjelle.470149ee709e.jpg",
        "url": "https://realpython.com/team/gahjelle/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Jim Anderson",
        "image": "https://realpython.com/cdn-cgi/image/width=700,height=700,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/jima.0b8f990b951a.jpg",
        "url": "https://realpython.com/team/janderson/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Joanna Jablonski",
        "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/jjablonksi-avatar.e37c4f83308e.jpg",
        "url": "https://realpython.com/team/jjablonski/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Kate Finegan",
        "image": "https://realpython.com/cdn-cgi/image/width=400,height=400,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/VZxEtUor_400x400.7169c68e3950.jpg",
        "url": "https://realpython.com/team/kfinegan/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Martin Breuss",
        "image": "https://realpython.com/cdn-cgi/image/width=456,height=456,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/martin_breuss_python_square.efb2b07faf9f.jpg",
        "url": "https://realpython.com/team/mbreuss/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      }
    ]
  },
  "datePublished": "2024-11-23T14:00:00+00:00",
  "dateModified": "2024-11-23T14:09:25.886830+00:00",
  "publisher": {
    "@type": "Organization",
    "@id": "https://realpython.com/#organization",
    "name": "Real Python",
    "url": "https://realpython.com",
    "logo": {
      "@type": "ImageObject",
      "url": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png",
      "width": 512,
      "height": 512
    },
    "description": "Real Python is a leading provider of online Python education and one of the largest language-specific online communities for software developers. It publishes high-quality learning resources, such as tutorials, books, and courses to an audience of millions of developers, data scientists, and machine learning engineers each month.",
    "slogan": "Become a Python Expert",
    "email": "info@realpython.com",
    "sameAs": [
      "https://github.com/realpython",
      "https://www.youtube.com/realpython",
      "https://twitter.com/realpython",
      "https://x.com/realpython",
      "https://www.linkedin.com/company/realpython-com/",
      "https://www.facebook.com/learnrealpython",
      "https://www.instagram.com/realpython",
      "https://www.tiktok.com/@realpython.com"
    ]
  },
  "author": {
    "@type": "Person",
    "name": "Leodanis Pozo Ramos",
    "image": "https://realpython.com/cdn-cgi/image/width=862,height=862,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Perfil_final1.9f896bc212f6.jpg",
    "url": "https://realpython.com/team/lpozoramos/",
    "affiliation": {
      "@type": "Organization",
      "@id": "https://realpython.com/#organization",
      "name": "Real Python",
      "url": "https://realpython.com",
      "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
    }
  },
  "description": "In this tutorial, you'll take a deep dive into how to iterate through a dictionary in Python. Dictionaries are a fundamental data type in Python, and you can solve various programming problems by iterating through them.",
  "hasPart": {
    "@type": "FAQPage",
    "mainEntity": [
      {
        "@type": "Question",
        "name": "What\u2019s the difference between iterating with .keys() and .values()?",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "

Using .keys() returns a view of the dictionary’s keys, allowing you to iterate through them. Conversely, .values() returns a view of the dictionary’s values. If you only need to work with keys or values, you can choose the appropriate method to make your code more explicit and readable.

" } }, { "@type": "Question", "name": "How do you iterate over a dictionary\u2019s keys and values in Python?", "acceptedAnswer": { "@type": "Answer", "text": "

You can iterate over a dictionary’s keys and values using the .items() method. This method returns a view object containing key-value pairs as tuples, which you can unpack directly in a for loop:

\n\n
\n Python\n \n
\n \n
\n
\n
\n
for key, value in dict_object.items():\n    print(key, value)\n
\n \n \n \n
\n
\n

In this example, you use key, value to unpack the tuples that you create during the iteration with .items().

" } }, { "@type": "Question", "name": "Can I iterate over a dictionary while modifying its content?", "acceptedAnswer": { "@type": "Answer", "text": "

Yes, you can! If you only need to update or modify the values of an existing dictionary, then you can safely do it in a loop because dictionaries are mutable, and you can change their values in place.

\n

On the other hand, if you need to remove key-value pairs from a dictionary while you’re looping through it, then you’d need to use a copy for the iteration and remove the values from the original dictionary. To create a shallow copy of a dictionary, you can use the .copy() method.

\n

You can also use a while loop and the .popitem() method to remove consecutive items from a dictionary without needing to make a copy beforehand.

\n

Sometimes, a better option is to use a dictionary comprehension to create a new dictionary with transformed values.

" } }, { "@type": "Question", "name": "How can I iterate through a dictionary in a specific order?", "acceptedAnswer": { "@type": "Answer", "text": "

If you want to iterate through a dictionary in sorted order, for example, then you can use the built-in sorted() function. If you feed this function with the result of .items(), then you’ll get a list of key-value tuples that you can traverse in a loop as usual.

\n

Additionally, you can use the built-in reversed() function to iterate through a Python dictionary in reverse order.

" } }, { "@type": "Question", "name": "How can I iterate through multiple dictionaries in one go?", "acceptedAnswer": { "@type": "Answer", "text": "

The collections and itertools standard-library modules provide the ChainMap class and the chain() function, respectively. Both tools allow you to combine multiple dictionaries and iterate through them in a chain. You’ll find a subtle behavior difference between these tools, though.

\n

When the input dictionaries have duplicate keys, ChainMap only gives you access to the first instance of a key, while chain() gives you access to all the instances of a repeated key.

\n

Finally, you can also use the dictionary unpacking operator (**) to merge multiple dictionaries together and iterate over the resulting dictionary. In this case, if the input dictionaries have duplicate keys, the last instance of every repeated key will prevail.

" } } ] } }

authorReal Python
twitter:cardsummary_large_image
twitter:imagehttps://files.realpython.com/media/How-to-Iterate-Through-A-Dictionary-in-Python_Watermarked.06d6547f531b.jpg
og:imagehttps://files.realpython.com/media/How-to-Iterate-Through-A-Dictionary-in-Python_Watermarked.06d6547f531b.jpg
twitter:creator@realpython
og:typearticle

Links:

https://realpython.com/
Start Herehttps://realpython.com/start-here/
Learn Python https://realpython.com/iterate-through-dictionary-python
Python Tutorials →In-depth articles and video courseshttps://realpython.com/search?kind=article&kind=course&order=newest
Learning Paths →Guided study plans for accelerated learninghttps://realpython.com/learning-paths/
Quizzes & Exercises →Check your learning progresshttps://realpython.com/quizzes/
Browse Topics →Focus on a specific area or skill levelhttps://realpython.com/tutorials/all/
Community Chat →Learn with other Pythonistashttps://realpython.com/community/
Office Hours →Live Q&A calls with Python expertshttps://realpython.com/office-hours/
Podcast →Hear what’s new in the world of Pythonhttps://realpython.com/podcasts/rpp/
Books →Round out your knowledge and learn offlinehttps://realpython.com/products/books/
Reference →Concise definitions for common Python termshttps://realpython.com/ref/
Code Mentor →BetaPersonalized code assistance & learning toolshttps://realpython.com/mentor/
Unlock All Content →https://realpython.com/account/join/
More https://realpython.com/iterate-through-dictionary-python
Learner Storieshttps://realpython.com/learner-stories/
Python Newsletterhttps://realpython.com/newsletter/
Python Job Boardhttps://www.pythonjobshq.com
Meet the Teamhttps://realpython.com/team/
Become a Tutorial Writerhttps://realpython.com/write-for-us/
Become a Video Instructorhttps://realpython.com/become-an-instructor/
Searchhttps://realpython.com/search
https://realpython.com/search
Joinhttps://realpython.com/account/join/
Sign‑Inhttps://realpython.com/account/login/?next=%2Fiterate-through-dictionary-python%2F
Browse Topicshttps://realpython.com/tutorials/all/
Guided Learning Pathshttps://realpython.com/learning-paths/
Basicshttps://realpython.com/search?level=basics
Intermediatehttps://realpython.com/search?level=intermediate
Advancedhttps://realpython.com/search?level=advanced
aihttps://realpython.com/tutorials/ai/
algorithmshttps://realpython.com/tutorials/algorithms/
apihttps://realpython.com/tutorials/api/
best-practiceshttps://realpython.com/tutorials/best-practices/
careerhttps://realpython.com/tutorials/career/
communityhttps://realpython.com/tutorials/community/
databaseshttps://realpython.com/tutorials/databases/
data-sciencehttps://realpython.com/tutorials/data-science/
data-structureshttps://realpython.com/tutorials/data-structures/
data-vizhttps://realpython.com/tutorials/data-viz/
devopshttps://realpython.com/tutorials/devops/
djangohttps://realpython.com/tutorials/django/
dockerhttps://realpython.com/tutorials/docker/
editorshttps://realpython.com/tutorials/editors/
flaskhttps://realpython.com/tutorials/flask/
front-endhttps://realpython.com/tutorials/front-end/
gamedevhttps://realpython.com/tutorials/gamedev/
guihttps://realpython.com/tutorials/gui/
machine-learninghttps://realpython.com/tutorials/machine-learning/
newshttps://realpython.com/tutorials/news/
numpyhttps://realpython.com/tutorials/numpy/
projectshttps://realpython.com/tutorials/projects/
pythonhttps://realpython.com/tutorials/python/
stdlibhttps://realpython.com/tutorials/stdlib/
testinghttps://realpython.com/tutorials/testing/
toolshttps://realpython.com/tutorials/tools/
web-devhttps://realpython.com/tutorials/web-dev/
web-scrapinghttps://realpython.com/tutorials/web-scraping/
Table of Contentshttps://realpython.com/iterate-through-dictionary-python#toc
Getting Started With Python Dictionarieshttps://realpython.com/iterate-through-dictionary-python#getting-started-with-python-dictionaries
Understanding How to Iterate Through a Dictionary in Pythonhttps://realpython.com/iterate-through-dictionary-python#understanding-how-to-iterate-through-a-dictionary-in-python
Traversing a Dictionary Directlyhttps://realpython.com/iterate-through-dictionary-python#traversing-a-dictionary-directly
Looping Over Dictionary Items: The .items() Methodhttps://realpython.com/iterate-through-dictionary-python#looping-over-dictionary-items-the-items-method
Iterating Through Dictionary Keys: The .keys() Methodhttps://realpython.com/iterate-through-dictionary-python#iterating-through-dictionary-keys-the-keys-method
Walking Through Dictionary Values: The .values() Methodhttps://realpython.com/iterate-through-dictionary-python#walking-through-dictionary-values-the-values-method
Changing Dictionary Values During Iterationhttps://realpython.com/iterate-through-dictionary-python#changing-dictionary-values-during-iteration
Safely Removing Items From a Dictionary During Iterationhttps://realpython.com/iterate-through-dictionary-python#safely-removing-items-from-a-dictionary-during-iteration
Iterating Through Dictionaries: for Loop Exampleshttps://realpython.com/iterate-through-dictionary-python#iterating-through-dictionaries-for-loop-examples
Filtering Items by Their Valuehttps://realpython.com/iterate-through-dictionary-python#filtering-items-by-their-value
Running Calculations With Keys and Valueshttps://realpython.com/iterate-through-dictionary-python#running-calculations-with-keys-and-values
Swapping Keys and Values Through Iterationhttps://realpython.com/iterate-through-dictionary-python#swapping-keys-and-values-through-iteration
Iterating Through Dictionaries: Comprehension Exampleshttps://realpython.com/iterate-through-dictionary-python#iterating-through-dictionaries-comprehension-examples
Filtering Items by Their Value: Revisitedhttps://realpython.com/iterate-through-dictionary-python#filtering-items-by-their-value-revisited
Swapping Keys and Values Through Iteration: Revisitedhttps://realpython.com/iterate-through-dictionary-python#swapping-keys-and-values-through-iteration-revisited
Traversing a Dictionary in Sorted and Reverse Orderhttps://realpython.com/iterate-through-dictionary-python#traversing-a-dictionary-in-sorted-and-reverse-order
Iterating Over Sorted Keyshttps://realpython.com/iterate-through-dictionary-python#iterating-over-sorted-keys
Looping Through Sorted Valueshttps://realpython.com/iterate-through-dictionary-python#looping-through-sorted-values
Sorting a Dictionary With a Comprehensionhttps://realpython.com/iterate-through-dictionary-python#sorting-a-dictionary-with-a-comprehension
Iterating Through a Dictionary in Reverse-Sorted Orderhttps://realpython.com/iterate-through-dictionary-python#iterating-through-a-dictionary-in-reverse-sorted-order
Traversing a Dictionary in Reverse Orderhttps://realpython.com/iterate-through-dictionary-python#traversing-a-dictionary-in-reverse-order
Iterating Over a Dictionary Destructively With .popitem()https://realpython.com/iterate-through-dictionary-python#iterating-over-a-dictionary-destructively-with-popitem
Using Built-in Functions to Implicitly Iterate Through Dictionarieshttps://realpython.com/iterate-through-dictionary-python#using-built-in-functions-to-implicitly-iterate-through-dictionaries
Applying a Transformation to a Dictionary’s Items: map()https://realpython.com/iterate-through-dictionary-python#applying-a-transformation-to-a-dictionarys-items-map
Filtering Items in a Dictionary: filter()https://realpython.com/iterate-through-dictionary-python#filtering-items-in-a-dictionary-filter
Traversing Multiple Dictionaries as Onehttps://realpython.com/iterate-through-dictionary-python#traversing-multiple-dictionaries-as-one
Iterating Through Multiple Dictionaries With ChainMaphttps://realpython.com/iterate-through-dictionary-python#iterating-through-multiple-dictionaries-with-chainmap
Iterating Through a Chain of Dictionaries With chain()https://realpython.com/iterate-through-dictionary-python#iterating-through-a-chain-of-dictionaries-with-chain
Looping Over Merged Dictionaries: The Unpacking Operator (**)https://realpython.com/iterate-through-dictionary-python#looping-over-merged-dictionaries-the-unpacking-operator
Frequently Asked Questionshttps://realpython.com/iterate-through-dictionary-python#frequently-asked-questions
https://realpython.com/feedback/survey/article/iterate-through-dictionary-python/liked/?from=article-sidebar
https://realpython.com/feedback/survey/article/iterate-through-dictionary-python/disliked/?from=article-sidebar
Python Dictionary Iteration: Advanced Tips & Tricks 47m · 9 lessons https://realpython.com/courses/python-dictionary-iteration/
Leodanis Pozo Ramoshttps://realpython.com/iterate-through-dictionary-python#author
https://realpython.com/iterate-through-dictionary-python#reader-comments
intermediatehttps://realpython.com/tutorials/intermediate/
pythonhttps://realpython.com/tutorials/python/
Getting Started With Python Dictionarieshttps://realpython.com/iterate-through-dictionary-python#getting-started-with-python-dictionaries
Understanding How to Iterate Through a Dictionary in Pythonhttps://realpython.com/iterate-through-dictionary-python#understanding-how-to-iterate-through-a-dictionary-in-python
Traversing a Dictionary Directlyhttps://realpython.com/iterate-through-dictionary-python#traversing-a-dictionary-directly
Looping Over Dictionary Items: The .items() Methodhttps://realpython.com/iterate-through-dictionary-python#looping-over-dictionary-items-the-items-method
Iterating Through Dictionary Keys: The .keys() Methodhttps://realpython.com/iterate-through-dictionary-python#iterating-through-dictionary-keys-the-keys-method
Walking Through Dictionary Values: The .values() Methodhttps://realpython.com/iterate-through-dictionary-python#walking-through-dictionary-values-the-values-method
Changing Dictionary Values During Iterationhttps://realpython.com/iterate-through-dictionary-python#changing-dictionary-values-during-iteration
Safely Removing Items From a Dictionary During Iterationhttps://realpython.com/iterate-through-dictionary-python#safely-removing-items-from-a-dictionary-during-iteration
Iterating Through Dictionaries: for Loop Exampleshttps://realpython.com/iterate-through-dictionary-python#iterating-through-dictionaries-for-loop-examples
Filtering Items by Their Valuehttps://realpython.com/iterate-through-dictionary-python#filtering-items-by-their-value
Running Calculations With Keys and Valueshttps://realpython.com/iterate-through-dictionary-python#running-calculations-with-keys-and-values
Swapping Keys and Values Through Iterationhttps://realpython.com/iterate-through-dictionary-python#swapping-keys-and-values-through-iteration
Iterating Through Dictionaries: Comprehension Exampleshttps://realpython.com/iterate-through-dictionary-python#iterating-through-dictionaries-comprehension-examples
Filtering Items by Their Value: Revisitedhttps://realpython.com/iterate-through-dictionary-python#filtering-items-by-their-value-revisited
Swapping Keys and Values Through Iteration: Revisitedhttps://realpython.com/iterate-through-dictionary-python#swapping-keys-and-values-through-iteration-revisited
Traversing a Dictionary in Sorted and Reverse Orderhttps://realpython.com/iterate-through-dictionary-python#traversing-a-dictionary-in-sorted-and-reverse-order
Iterating Over Sorted Keyshttps://realpython.com/iterate-through-dictionary-python#iterating-over-sorted-keys
Looping Through Sorted Valueshttps://realpython.com/iterate-through-dictionary-python#looping-through-sorted-values
Sorting a Dictionary With a Comprehensionhttps://realpython.com/iterate-through-dictionary-python#sorting-a-dictionary-with-a-comprehension
Iterating Through a Dictionary in Reverse-Sorted Orderhttps://realpython.com/iterate-through-dictionary-python#iterating-through-a-dictionary-in-reverse-sorted-order
Traversing a Dictionary in Reverse Orderhttps://realpython.com/iterate-through-dictionary-python#traversing-a-dictionary-in-reverse-order
Iterating Over a Dictionary Destructively With .popitem()https://realpython.com/iterate-through-dictionary-python#iterating-over-a-dictionary-destructively-with-popitem
Using Built-in Functions to Implicitly Iterate Through Dictionarieshttps://realpython.com/iterate-through-dictionary-python#using-built-in-functions-to-implicitly-iterate-through-dictionaries
Applying a Transformation to a Dictionary’s Items: map()https://realpython.com/iterate-through-dictionary-python#applying-a-transformation-to-a-dictionarys-items-map
Filtering Items in a Dictionary: filter()https://realpython.com/iterate-through-dictionary-python#filtering-items-in-a-dictionary-filter
Traversing Multiple Dictionaries as Onehttps://realpython.com/iterate-through-dictionary-python#traversing-multiple-dictionaries-as-one
Iterating Through Multiple Dictionaries With ChainMaphttps://realpython.com/iterate-through-dictionary-python#iterating-through-multiple-dictionaries-with-chainmap
Iterating Through a Chain of Dictionaries With chain()https://realpython.com/iterate-through-dictionary-python#iterating-through-a-chain-of-dictionaries-with-chain
Looping Over Merged Dictionaries: The Unpacking Operator (**)https://realpython.com/iterate-through-dictionary-python#looping-over-merged-dictionaries-the-unpacking-operator
Frequently Asked Questionshttps://realpython.com/iterate-through-dictionary-python#frequently-asked-questions
Remove adshttps://realpython.com/account/join/
Python Dictionary Iteration: Advanced Tips & Trickshttps://realpython.com/courses/python-dictionary-iteration/
dictionarieshttps://realpython.com/python-dicts/
forhttps://realpython.com/python-for-loop/
comprehensionshttps://realpython.com/list-comprehension-python/
map()https://realpython.com/python-map-function/
filter()https://realpython.com/python-filter-function/
itertoolshttps://realpython.com/python-itertools/
collectionshttps://realpython.com/python-collections-module/
Click here to download the sample codehttps://realpython.com/bonus/iterate-through-dictionary-python-code/
https://realpython.com/quizzes/python-dictionary-iteration/
Python Dictionary Iterationhttps://realpython.com/quizzes/python-dictionary-iteration/
https://realpython.com/iterate-through-dictionary-python#getting-started-with-python-dictionaries
Moduleshttps://realpython.com/python-modules-packages/
classeshttps://realpython.com/python-classes/
globals()https://realpython.com/python-scope-legb-rule/#globals
locals()https://realpython.com/python-scope-legb-rule/#locals
official documentationhttps://docs.python.org/3/index.html
Sourcehttps://docs.python.org/3/glossary.html#term-dictionary
hashablehttps://docs.python.org/3/glossary.html#term-hashable
sequenceshttps://docs.python.org/3/glossary.html#term-sequence
iterableshttps://realpython.com/python-iterators-iterables/#getting-to-know-python-iterables
sethttps://realpython.com/python-sets/
mutablehttps://docs.python.org/3/glossary.html#term-mutable
CPythonhttps://realpython.com/cpython-source-code-guide/
PyPyhttps://realpython.com/pypy-faster-python/
IronPythonhttp://ironpython.net/
Jythonhttp://www.jython.org/index.html
mutablehttps://realpython.com/python-mutable-vs-immutable-types/#dictionaries
in placehttps://en.wikipedia.org/wiki/In-place_algorithm
Remove adshttps://realpython.com/account/join/
https://realpython.com/iterate-through-dictionary-python#understanding-how-to-iterate-through-a-dictionary-in-python
for loopshttps://realpython.com/python-for-loop/
https://realpython.com/iterate-through-dictionary-python#traversing-a-dictionary-directly
special methodshttps://realpython.com/python-classes/#special-methods-and-protocols
double underscorehttps://realpython.com/python-double-underscore/
dir()https://realpython.com/python-scope-legb-rule/#dir
dicthttps://docs.python.org/3/library/stdtypes.html#dict
iteratorhttps://realpython.com/python-iterators-iterables/#getting-to-know-python-iterators
iterator objecthttps://docs.python.org/3/glossary.html#term-iterator
.__iter__()https://docs.python.org/3/library/stdtypes.html#iterator.__iter__
https://realpython.com/iterate-through-dictionary-python#looping-over-dictionary-items-the-items-method
view objecthttps://docs.python.org/3/library/stdtypes.html#dict-views
tuplehttps://realpython.com/python-lists-tuples/#python-tuples
type()https://docs.python.org/3/library/functions.html#type
tuple unpackinghttps://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences
variableshttps://realpython.com/python-variables/
Remove adshttps://realpython.com/account/join/
https://realpython.com/iterate-through-dictionary-python#iterating-through-dictionary-keys-the-keys-method
https://realpython.com/iterate-through-dictionary-python#walking-through-dictionary-values-the-values-method
https://realpython.com/iterate-through-dictionary-python#changing-dictionary-values-during-iteration
https://realpython.com/iterate-through-dictionary-python#safely-removing-items-from-a-dictionary-during-iteration
delhttps://realpython.com/python-del-statement/
.pop()https://docs.python.org/3/library/stdtypes.html#dict.pop
Remove adshttps://realpython.com/account/join/
https://realpython.com/iterate-through-dictionary-python#iterating-through-dictionaries-for-loop-examples
comprehension exampleshttps://realpython.com/iterate-through-dictionary-python#iterating-through-dictionaries-comprehension-examples
https://realpython.com/iterate-through-dictionary-python#filtering-items-by-their-value
conditional statementhttps://realpython.com/python-conditional-statements/
setshttps://realpython.com/python-sets/
unionhttps://docs.python.org/3/library/stdtypes.html#frozenset.union
intersectionhttps://docs.python.org/3/library/stdtypes.html#frozenset.intersection
differencehttps://docs.python.org/3/library/stdtypes.html#frozenset.difference
https://realpython.com/iterate-through-dictionary-python#running-calculations-with-keys-and-values
augmented assignmenthttps://realpython.com/python-assignment-operator/#augmented-assignment-operators-in-python
sum()https://realpython.com/python-sum-function/
Remove adshttps://realpython.com/account/join/
https://realpython.com/iterate-through-dictionary-python#swapping-keys-and-values-through-iteration
zip()https://realpython.com/python-zip-function/
constructorhttps://realpython.com/python-class-constructor/#getting-to-know-pythons-class-constructors
https://realpython.com/iterate-through-dictionary-python#iterating-through-dictionaries-comprehension-examples
list comprehensionshttps://realpython.com/list-comprehension-python/
https://realpython.com/iterate-through-dictionary-python#filtering-items-by-their-value-revisited
Earlierhttps://realpython.com/iterate-through-dictionary-python#filtering-items-in-a-dictionary-filter
https://realpython.com/iterate-through-dictionary-python#swapping-keys-and-values-through-iteration-revisited
Remove adshttps://realpython.com/account/join/
https://realpython.com/iterate-through-dictionary-python#traversing-a-dictionary-in-sorted-and-reverse-order
sorted()https://realpython.com/python-sort/
Sorting a Python Dictionary: Values, Keys, and Morehttps://realpython.com/sort-python-dictionary/
reversed()https://docs.python.org/3/library/functions.html#reversed
https://realpython.com/iterate-through-dictionary-python#iterating-over-sorted-keys
data typehttps://realpython.com/python-data-types/
sorting stringshttps://realpython.com/python-list/#sorting-a-list-sorted-and-sort
Unicodehttps://realpython.com/python-encodings-guide/
https://realpython.com/iterate-through-dictionary-python#looping-through-sorted-values
keyword-only argumenthttps://realpython.com/defining-your-own-python-function/#keyword-only-arguments
lambdahttps://realpython.com/python-lambda/
https://realpython.com/iterate-through-dictionary-python#sorting-a-dictionary-with-a-comprehension
Remove adshttps://realpython.com/account/join/
https://realpython.com/iterate-through-dictionary-python#iterating-through-a-dictionary-in-reverse-sorted-order
Boolean valuehttps://realpython.com/python-boolean/
https://realpython.com/iterate-through-dictionary-python#traversing-a-dictionary-in-reverse-order
iteratorhttps://realpython.com/python-iterators-iterables/#getting-to-know-python-iterators
https://realpython.com/iterate-through-dictionary-python#iterating-over-a-dictionary-destructively-with-popitem
LIFOhttps://en.wikipedia.org/wiki/Stack_(abstract_data_type)
KeyErrorhttps://realpython.com/python-keyerror/
whilehttps://realpython.com/python-while-loop/
exception handlinghttps://realpython.com/python-exceptions/#the-try-and-except-block-handling-exceptions
falsyhttps://realpython.com/python-boolean/#python-boolean-testing
LBYL vs EAFPhttps://realpython.com/python-lbyl-vs-eafp/
https://realpython.com/iterate-through-dictionary-python#using-built-in-functions-to-implicitly-iterate-through-dictionaries
map()https://realpython.com/python-map-function/
filter()https://realpython.com/python-filter-function/
Remove adshttps://realpython.com/account/join/
https://realpython.com/iterate-through-dictionary-python#applying-a-transformation-to-a-dictionarys-items-map
define a functionhttps://realpython.com/defining-your-own-python-function/
https://realpython.com/iterate-through-dictionary-python#filtering-items-in-a-dictionary-filter
https://realpython.com/iterate-through-dictionary-python#traversing-multiple-dictionaries-as-one
collectionshttps://realpython.com/python-collections-module/
itertoolshttps://realpython.com/python-itertools/
standard libraryhttps://docs.python.org/3/library/index.html
ChainMaphttps://realpython.com/python-chainmap/
chain()https://docs.python.org/3/library/itertools.html#itertools.chain
https://realpython.com/iterate-through-dictionary-python#iterating-through-multiple-dictionaries-with-chainmap
Remove adshttps://realpython.com/account/join/
https://realpython.com/iterate-through-dictionary-python#iterating-through-a-chain-of-dictionaries-with-chain
https://realpython.com/iterate-through-dictionary-python#looping-over-merged-dictionaries-the-unpacking-operator
unpacking generalizationhttps://www.python.org/dev/peps/pep-0448
https://realpython.com/iterate-through-dictionary-python#frequently-asked-questions
https://realpython.com/quizzes/python-dictionary-iteration/
Python Dictionary Iterationhttps://realpython.com/quizzes/python-dictionary-iteration/
https://realpython.com/feedback/survey/article/iterate-through-dictionary-python/liked/?from=article-footer
https://realpython.com/feedback/survey/article/iterate-through-dictionary-python/disliked/?from=article-footer
Python Dictionary Iteration: Advanced Tips & Trickshttps://realpython.com/courses/python-dictionary-iteration/
https://realpython.com/team/lpozoramos/
» More about Leodanishttps://realpython.com/team/lpozoramos/
https://realpython.com/team/asantos/
Aldrenhttps://realpython.com/team/asantos/
https://realpython.com/team/bweleschuk/
Brendahttps://realpython.com/team/bweleschuk/
https://realpython.com/team/gahjelle/
Geir Arnehttps://realpython.com/team/gahjelle/
https://realpython.com/team/janderson/
Jimhttps://realpython.com/team/janderson/
https://realpython.com/team/jjablonski/
Joannahttps://realpython.com/team/jjablonski/
https://realpython.com/team/kfinegan/
Katehttps://realpython.com/team/kfinegan/
https://realpython.com/team/mbreuss/
Martinhttps://realpython.com/team/mbreuss/
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=iterate-through-dictionary-python
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=iterate-through-dictionary-python
https://realpython.com/feedback/survey/article/iterate-through-dictionary-python/liked/?from=article-comments
https://realpython.com/feedback/survey/article/iterate-through-dictionary-python/disliked/?from=article-comments
LinkedInhttps://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Frealpython.com%2Fiterate-through-dictionary-python%2F
Twitterhttps://twitter.com/intent/tweet/?text=Interesting%20Python%20article%20on%20%40realpython%3A%20How%20to%20Iterate%20Through%20a%20Dictionary%20in%20Python&url=https%3A%2F%2Frealpython.com%2Fiterate-through-dictionary-python%2F
Blueskyhttps://bsky.app/intent/compose?text=Interesting%20Python%20article%20on%20%40realpython.com%3A%20How%20to%20Iterate%20Through%20a%20Dictionary%20in%20Python%20https%3A%2F%2Frealpython.com%2Fiterate-through-dictionary-python%2F
Facebookhttps://facebook.com/sharer/sharer.php?u=https%3A%2F%2Frealpython.com%2Fiterate-through-dictionary-python%2F
Get tips for asking good questionshttps://realpython.com/python-beginner-tips/#tip-9-ask-good-questions
get answers to common questions in our support portalhttps://support.realpython.com
Real Python Community Chathttps://realpython.com/community/
“Office Hours” Live Q&A Sessionhttps://realpython.com/office-hours/
intermediatehttps://realpython.com/tutorials/intermediate/
pythonhttps://realpython.com/tutorials/python/
Python Dictionary Iteration: Advanced Tips & Trickshttps://realpython.com/courses/python-dictionary-iteration/?utm_source=realpython&utm_medium=web&utm_campaign=related-course&utm_content=iterate-through-dictionary-python
Dictionaries in Pythonhttps://realpython.com/python-dicts/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=iterate-through-dictionary-python
Sending Emails With Pythonhttps://realpython.com/python-send-email/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=iterate-through-dictionary-python
Working With JSON Data in Pythonhttps://realpython.com/python-json/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=iterate-through-dictionary-python
Sorting a Python Dictionary: Values, Keys, and Morehttps://realpython.com/sort-python-dictionary/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=iterate-through-dictionary-python
Python's raise: Effectively Raising Exceptions in Your Codehttps://realpython.com/python-raise-exception/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=iterate-through-dictionary-python
https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fiterate-through-dictionary-python%2F
Continue »https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fiterate-through-dictionary-python%2F
Sign-Inhttps://realpython.com/account/login/?next=/iterate-through-dictionary-python/
Start Herehttps://realpython.com/start-here/
Learning Resourceshttps://realpython.com/search
Code Mentorhttps://realpython.com/mentor/
Python Referencehttps://realpython.com/ref/
Python Cheat Sheethttps://realpython.com/cheatsheets/python/
Support Centerhttps://support.realpython.com/
Learning Pathshttps://realpython.com/learning-paths/
Quizzes & Exerciseshttps://realpython.com/quizzes/
Browse Topicshttps://realpython.com/tutorials/all/
Live Courseshttps://realpython.com/live/
Bookshttps://realpython.com/books/
Podcasthttps://realpython.com/podcasts/rpp/
Newsletterhttps://realpython.com/newsletter/
Community Chathttps://realpython.com/community/
Office Hourshttps://realpython.com/office-hours/
Learner Storieshttps://realpython.com/learner-stories/
Plans & Pricinghttps://realpython.com/account/join/
Team Planshttps://realpython.com/account/join-team/
For Businesshttps://realpython.com/account/join-team/inquiry/
For Schoolshttps://realpython.com/account/join-team/education-inquiry/
Reviewshttps://realpython.com/learner-stories/
About Ushttps://realpython.com/about/
Teamhttps://realpython.com/team/
Mission & Valueshttps://realpython.com/mission/
Editorial Guidelineshttps://realpython.com/editorial-guidelines/
Sponsorshipshttps://realpython.com/sponsorships/
Careershttps://realpython.workable.com
Press Kithttps://realpython.com/media-kit/
Merchhttps://realpython.com/merch
https://www.youtube.com/realpython
https://x.com/realpython
https://www.linkedin.com/company/realpython-com
https://www.facebook.com/LearnRealPython
https://github.com/realpython/
Privacy Policyhttps://realpython.com/privacy-policy/
Terms of Usehttps://realpython.com/terms/
Securityhttps://realpython.com/security/
Contacthttps://realpython.com/contact/
https://realpython.com/

Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover

Robots: max-image-preview:large


URLs of crawlers that visited me.