Skip to content

Instantly share code, notes, and snippets.

@shravan-kuchkula
Created April 19, 2017 01:06
Show Gist options
  • Save shravan-kuchkula/6ca3054d5ec0549e1759d739b3d47513 to your computer and use it in GitHub Desktop.
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)
# 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