From ece05ed413748746c54f5f818f8f7a1dd114774b Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Sat, 3 Oct 2020 17:24:50 +0300 Subject: [PATCH] Update to_dictionary Fixes #203 --- snippets/to_dictionary.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/to_dictionary.md b/snippets/to_dictionary.md index ecf7e40ff..849622a5e 100644 --- a/snippets/to_dictionary.md +++ b/snippets/to_dictionary.md @@ -6,11 +6,11 @@ tags: list,dictionary,intermediate Combines two lists into a dictionary, where the elements of the first one serve as the keys and the elements of the second one serve as the values. The values of the first list need to be unique and hashable. -- Use `zip()` in combination with a list comprehension to combine the values of the two lists, based on their positions. +- Use `zip()` in combination with the `dict()` constructor to combine the values of the two lists into a dictionary. ```py def to_dictionary(keys, values): - return {key:value for key, value in zip(keys, values)} + return dict(zip(keys, values)) ``` ```py