Loading section...
Dictionary Gotchas
Even experienced developers make these mistakes. Being aware of these gotchas helps you avoid subtle bugs. Modifying During Iteration Adding or removing keys while iterating causes a RuntimeError. If you need to modify, iterate over a copy: Mutable Default Arguments Using a dictionary as a default argument is a famous Python pitfall. The default is created once and shared across all calls: Integer Key Confusion In Python, the integer 1 and the boolean True hash to the same value. This can lead to unexpected overwrites: This loop tries to remove small values from a dictionary, but it crashes. Fix the bug by removing the tile that causes the runtime error. Dictionaries power many architectural decisions in real systems. Practice choosing the right dictionary-based pattern for a data engineer