MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Python Toolbox

Lihat Kursus

Petunjuk latihan

  • 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.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Zip lists: zipped_lists
zipped_lists = ____

# Create a dictionary: rs_dict
rs_dict = ____

# Print the dictionary
print(rs_dict)
Edit dan Jalankan Kode