From 2947fdfe6a47a064bab8199ab1381ef4f1c3455b Mon Sep 17 00:00:00 2001 From: DJHills <20931105+DJHills@users.noreply.github.com> Date: Fri, 9 Jan 2026 17:00:47 +0000 Subject: [PATCH] Point out that output of zip can be passed directly to dict --- .../DataStructures_II_Dictionaries.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Python/Module2_EssentialsOfPython/DataStructures_II_Dictionaries.md b/Python/Module2_EssentialsOfPython/DataStructures_II_Dictionaries.md index 77572dd4..64ad674e 100644 --- a/Python/Module2_EssentialsOfPython/DataStructures_II_Dictionaries.md +++ b/Python/Module2_EssentialsOfPython/DataStructures_II_Dictionaries.md @@ -446,10 +446,13 @@ for index in range(len(names)): grades[name] = value ``` -You should make use of the function [zip](https://www.pythonlikeyoumeanit.com/Module2_EssentialsOfPython/Itertools.html#zip) to pair the names and scores together in an iterable, and create the dictionary using a comprehension expression. +You should make use of the function [zip](https://www.pythonlikeyoumeanit.com/Module2_EssentialsOfPython/Itertools.html#zip) to pair the names and scores together in an iterable, which can then be passed to `dict` or used in a comprehension expression. ```python -# much better solution for creating `grades` +# pass iterable output of `zip` straight to `dict` +grades = dict(zip(names, scores)) + +# alternatively, iterate over output of `zip` using a comprehension expression grades = {student:value for student, value in zip(names, scores)} # updating Zoe's grade