Created
April 19, 2017 01:06
-
-
Save shravan-kuchkula/6ca3054d5ec0549e1759d739b3d47513 to your computer and use it in GitHub Desktop.
Create a dictionary from 2 lists, one contains the keys, the other contains the values. (Python)
This file contains 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
# Define lists2dict() | |
def lists2dict(list1, list2): | |
"""Return a dictionary where list1 provides | |
the keys and list2 provides the values.""" | |
# Zip lists: zipped_lists | |
zipped_lists = zip(list1, list2) | |
# Create a dictionary: rs_dict | |
rs_dict = dict(zipped_lists) | |
# Return the dictionary | |
return rs_dict | |
# Call lists2dict: rs_fxn | |
rs_fxn = lists2dict(feature_names, row_vals) | |
# Print rs_fxn | |
print(rs_fxn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment