0
0
Pythonprogramming~15 mins

Creating dictionary from two sequences in Python - Try It Yourself

Choose your learning style9 modes available
Creating dictionary from two sequences
๐Ÿ“– Scenario: You have two lists: one with product names and another with their prices. You want to combine them into a dictionary where each product name is a key and its price is the value.
๐ŸŽฏ Goal: Build a dictionary from two lists using Python, matching each product with its price.
๐Ÿ“‹ What You'll Learn
Create two lists named products and prices with exact values
Create a variable called product_price_dict to hold the dictionary
Use a Python method to combine products and prices into product_price_dict
Print the product_price_dict to show the final dictionary
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Combining two related lists into a dictionary is common when working with data like product catalogs, student grades, or contact information.
๐Ÿ’ผ Career
This skill is useful for data processing, web development, and automation tasks where you need to organize paired data efficiently.
Progress0 / 4 steps
1
Create the product and price lists
Create a list called products with these exact values: 'apple', 'banana', 'cherry'. Also create a list called prices with these exact values: 0.99, 0.50, 2.00.
Python
Need a hint?

Use square brackets [] to create lists and separate items with commas.

2
Prepare the dictionary variable
Create an empty dictionary called product_price_dict to store the combined product-price pairs.
Python
Need a hint?

Use curly braces {} to create an empty dictionary.

3
Combine the lists into a dictionary
Use the zip function with products and prices to create product_price_dict by converting the zipped pairs into a dictionary.
Python
Need a hint?

The zip function pairs items from two lists. Then dict() converts those pairs into a dictionary.

4
Print the dictionary
Print the product_price_dict to display the combined dictionary of products and prices.
Python
Need a hint?

Use the print() function to show the dictionary on the screen.