From 9c2ebfebc0c15af21dea0ad0b2cfdc2990acde18 Mon Sep 17 00:00:00 2001 From: Real Python Bot <42617967+realpython-bot@users.noreply.github.com> Date: Wed, 21 Oct 2026 15:35:00 +0000 Subject: [PATCH] Sync python-dicts with the maintenance update of Dictionaries in Python - dict_zip.py: match the article's zip() example (places/teams) and drop zip(strict=False), which needs Python 3.10 and broke the 3.9 floor - membership.py: use 1_000_000 as in the article's script - README.md: state the Python 3.9 floor (dict | and |=) Co-Authored-By: Claude Opus 5.5 --- python-dicts/README.md | 2 ++ python-dicts/dict_zip.py | 20 +++++++++++++++++--- python-dicts/membership.py | 8 ++++---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/python-dicts/README.md b/python-dicts/README.md index ac4a108380..c957af0315 100644 --- a/python-dicts/README.md +++ b/python-dicts/README.md @@ -1,3 +1,5 @@ # Dictionaries in Python This folder provides the code examples for the Real Python tutorial [Dictionaries in Python](https://realpython.com/python-dicts/). + +The code requires Python 3.9 or later and has no third-party dependencies. diff --git a/python-dicts/dict_zip.py b/python-dicts/dict_zip.py index 58ad9ff66d..23055ebc6c 100644 --- a/python-dicts/dict_zip.py +++ b/python-dicts/dict_zip.py @@ -1,4 +1,18 @@ -cities = ["Colorado", "Chicago", "Boston", "Minnesota", "Milwaukee", "Seattle"] -teams = ["Rockies", "White Sox", "Red Sox", "Twins", "Brewers", "Mariners"] +places = [ + "Colorado", + "Chicago", + "Boston", + "Minnesota", + "Milwaukee", + "Seattle", +] +teams = [ + "Rockies", + "White Sox", + "Red Sox", + "Twins", + "Brewers", + "Mariners", +] -print(dict(zip(cities, teams, strict=False))) +print(dict(zip(places, teams))) diff --git a/python-dicts/membership.py b/python-dicts/membership.py index b3c1d6fc0e..1494f30621 100644 --- a/python-dicts/membership.py +++ b/python-dicts/membership.py @@ -11,16 +11,16 @@ # Run timeit to compare the membership test time_in_dict = timeit.timeit( - '"Milwaukee" in MLB_teams', globals=globals(), number=1000000 + '"Milwaukee" in MLB_teams', globals=globals(), number=1_000_000 ) time_in_keys = timeit.timeit( - '"Milwaukee" in MLB_teams.keys()', globals=globals(), number=1000000 + '"Milwaukee" in MLB_teams.keys()', globals=globals(), number=1_000_000 ) time_not_in_dict = timeit.timeit( - '"Indianapolis" in MLB_teams', globals=globals(), number=1000000 + '"Indianapolis" in MLB_teams', globals=globals(), number=1_000_000 ) time_not_in_keys = timeit.timeit( - '"Indianapolis" in MLB_teams.keys()', globals=globals(), number=1000000 + '"Indianapolis" in MLB_teams.keys()', globals=globals(), number=1_000_000 ) print(