Iterating Over Dictionaries

Iterating means looping through each item in a collection. With lists, you iterate over elements by position. With dictionaries, you have three choices: iterate over keys, values, or both. Let's explore each approach. Iterating Over Keys When you loop directly over a dictionary, you iterate over its keys. This is the default behavior and the most common pattern: Iterating Over Values Iterating Keys and Values Fill in the blanks to complete two tasks: sum up all the prices, then get a list of all item names. Since Python 3.7, dictionary order is guaranteed to be insertion order. This means looping over keys, values, or items always produces them in the order they were added, making dictionary iteration predictable.

About This Interactive Section

This section is part of the Dictionaries: Intermediate lesson on DataDriven, a free data engineering interview prep platform. Each section includes explanations, worked examples, and hands-on code challenges that execute in real time. SQL queries run against a live PostgreSQL database. Python runs in a sandboxed Docker container. Data modeling problems validate against interactive schema canvases. All content is framed around what data engineering interviewers actually test at companies like Meta, Google, Amazon, Netflix, Stripe, and Databricks.

How DataDriven Lessons Work

DataDriven combines four interview rounds (SQL, Python, Data Modeling, Pipeline Architecture) with adaptive difficulty and spaced repetition. Easy problems get harder as you improve. Weak concepts resurface until you master them. Your readiness score tracks progress across every topic interviewers test. Every lesson section ends with problems you solve by writing and running real code, not by picking multiple-choice answers.