Last active
May 8, 2020 19:31
-
-
Save raeq/cf3aa312343cca9b5c9bbbc0913bf3b2 to your computer and use it in GitHub Desktop.
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
""" | |
Zipping two lists to a dictionary as an example of dict comprehension. | |
""" | |
import typing | |
def dict_from_list(keys: [typing.Hashable], values: [])-> typing.Dict: | |
""" | |
Zips two lists. Returns: dict | |
""" | |
if len(keys) != len(values): | |
raise ValueError("Sequences are different lengths.") | |
return dict(zip(keys, values)) | |
countries: list = ["China", "India", "United States", "Indonesia", "Pakistan"] | |
population_m: list = [1400, 1360, 330, 270, 221] | |
print(dict_from_list(countries, population_m)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment