Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Python Toolbox

Cursus bekijken

Oefeninstructies

  • Create a zip object by calling zip() and passing to it feature_names and row_vals. Assign the result to zipped_lists.
  • Create a dictionary from the zipped_lists zip object by calling dict() with zipped_lists. Assign the resulting dictionary to rs_dict.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Zip lists: zipped_lists
zipped_lists = ____

# Create a dictionary: rs_dict
rs_dict = ____

# Print the dictionary
print(rs_dict)
Code bewerken en uitvoeren