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(