Zipping dictionaries
For this exercise, you'll use what you've learned about the zip()
function and combine two lists into a dictionary.
These lists are actually extracted from a bigger dataset file of world development indicators from the World Bank. For pedagogical purposes, we have pre-processed this dataset into the lists that you'll be working with.
The first list feature_names
contains header names of the dataset and the second list row_vals
contains actual values of a row from the dataset, corresponding to each of the header names.
This exercise is part of the course
Python Toolbox
Exercise instructions
- Create a zip object by calling
zip()
and passing to itfeature_names
androw_vals
. Assign the result tozipped_lists
. - Create a dictionary from the
zipped_lists
zip object by callingdict()
withzipped_lists
. Assign the resulting dictionary tors_dict
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Zip lists: zipped_lists
zipped_lists = ____
# Create a dictionary: rs_dict
rs_dict = ____
# Print the dictionary
print(rs_dict)