Created
August 1, 2020 18:25
-
-
Save raeq/6e5443662e3afa732fbbe5f9d4439e4c to your computer and use it in GitHub Desktop.
Return a dict from two lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dict_from_two_lists(keys: list, values: list) -> dict: | |
""" | |
Args: | |
keys: The list of keys for the dictionary | |
values: The list of values for the dictionary | |
Returns: A dictionary of key:value pairs | |
""" | |
if len(keys) != len(values): | |
raise ValueError("Lists must be of same length") | |
return dict(zip(keys, values)) | |
assert dict_from_two_lists(["first", "second", "third"], | |
["primary", "secondary", "tertiary"]) == { | |
"first": "primary", | |
"second": "secondary", | |
"third": "tertiary", | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment