Pages

Topics

Tools

↑↓navigate↵openescclose

Python guides

Every published Python guide, newest first, with practical examples you can copy into your own project.

3,965 guides across 14 topics

Topics

Latest Python guides

Illustration of a Python dictionary shallow copy showing shared references to nested objects.
Python

Python Shallow Copy for Dictionaries: How It Works and When to Use It

Understand Python shallow copy for dicts: how dict.copy() works, its limits with nested values, and when to use copy.deepcopy() instead.

Pythondictionaryshallow copydeep copy
Diagram showing shallow and deep copy of a Python dictionary with nested structures.
Python

Python Dict Copy: Shallow vs Deep Copy

Learn how to copy dictionaries in Python: assignment vs .copy(), shallow vs deep copy, and when to use copy.deepcopy().

python-dictshallow-copydeep-copycopy-module
Illustration of a Python dictionary with a length measurement.
Python

Python Dictionary Length: Using len() Correctly

Learn how to get the length of a Python dictionary with len(), what it counts, and common pitfalls to avoid.

pythondictionarylendata structures
A Python dictionary with a magnifying glass over its values, illustrating a value membership check.
Python

Python Dictionary Contains Value: How to Check

Check whether a Python dictionary contains a specific value using `in` with `values()`, understand NaN and equality edge cases, and know when to use sets or reverse mappings for repeated lookups.

dictionarymembership testvaluesperformance
Illustration of a Python dictionary with a magnifying glass over a key, representing key existence check.
Python

Python Dictionary Contains Key: Check Existence with in

python dictionary contains key: Learn how to check if a key exists in a Python dictionary using the in operator, get(), and other methods, with practical examples and...

dictionarykey lookupmembership testpython syntax
Illustration of a Python dictionary being iterated with key-value pairs flowing through a loop
Python

Python Dictionary Items Iteration Explained

python dictionary items iteration: Learn how to iterate over Python dictionary items with .items(), handle mutation errors, and understand view behavior and ordering.

dictionary iterationdict_items viewPython loopsruntime errors
Illustration of iterating over dictionary values in Python, showing a loop over a dict with key-value pairs.
Python

Python Dictionary Value Iteration Explained

Learn how to iterate over dictionary values in Python with .values(), .items(), and comprehensions, including performance tradeoffs and safe modification.

dictionary iterationPython loopsvalues() methoditems() method
Diagram showing iteration over a dictionary's keys with a loop and a key-value pair view.
Python

Python Dictionary Key Iteration: Methods and Pitfalls

Learn how to iterate over dictionary keys in Python, including direct for loops, .keys(), .items(), insertion-order guarantees, and safe modification during iteration.

dictionary iterationpython loopsdict keysiteration methods
Illustration of a Python dictionary iteration loop showing keys and values.
Python

Python Dictionary Foreach: Iterate Keys, Values, Pairs

Learn how to use Python for loops to iterate over dictionary keys, values, and key-value pairs, and modify dictionaries safely.

Pythondictionaryiterationitems()
Illustration of a Python dictionary iteration showing key-value pairs in a loop.
Python

How to Iterate Over a Python Dictionary: Methods and Pitfalls

Learn the correct ways to iterate over Python dictionaries, including key, value, and item access, order guarantees, and safe modification.

pythondictionaryiterationloops