Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Dictionaries: Storing Paired Information | Organizing and Summarizing Data
Python for Daily Tasks

bookDictionaries: Storing Paired Information

Dictionaries in Python are powerful tools for pairing related information. Unlike lists, which store items in a sequence, dictionaries use a key-value structure. This means each piece of data (the value) is associated with a unique identifier (the key). You can think of a dictionary as a real-world dictionary: you look up a word (the key) to find its definition (the value). In Python, dictionaries are created using curly braces {} and key-value pairs separated by colons. This structure is especially useful when you need to keep track of information that naturally comes in pairs, such as item names and their prices or tasks and their deadlines.

123456789
# Create a dictionary to store items and their prices item_prices = { "apple": 0.99, "banana": 0.59, "bread": 2.49, "milk": 1.99 } print(item_prices)
copy

To work with dictionaries, you need to know how to access, update, and add key-value pairs. To access the value for a specific key, use square brackets with the key name, like item_prices["apple"]. If you want to update the price of an existing item, assign a new value to its key. To add a new item, simply assign a value to a new key. These operations make dictionaries flexible for organizing and summarizing paired data in your daily tasks.

1234567
# Update the price of an existing item item_prices["banana"] = 0.69 # Add a new item to the dictionary item_prices["eggs"] = 2.99 print(item_prices)
copy

1. What is a key in a Python dictionary?

2. How do you access the value associated with a key?

3. Fill in the blanks to add a new key-value pair to a dictionary.

question mark

What is a key in a Python dictionary?

Select the correct answer

question mark

How do you access the value associated with a key?

Select the correct answer

question-icon

Fill in the blanks to add a new key-value pair to a dictionary.

=
{'laundry': 'Saturday', 'groceries': 'Sunday'}

Click or drag`n`drop items and fill in the blanks

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 2

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

bookDictionaries: Storing Paired Information

Scorri per mostrare il menu

Dictionaries in Python are powerful tools for pairing related information. Unlike lists, which store items in a sequence, dictionaries use a key-value structure. This means each piece of data (the value) is associated with a unique identifier (the key). You can think of a dictionary as a real-world dictionary: you look up a word (the key) to find its definition (the value). In Python, dictionaries are created using curly braces {} and key-value pairs separated by colons. This structure is especially useful when you need to keep track of information that naturally comes in pairs, such as item names and their prices or tasks and their deadlines.

123456789
# Create a dictionary to store items and their prices item_prices = { "apple": 0.99, "banana": 0.59, "bread": 2.49, "milk": 1.99 } print(item_prices)
copy

To work with dictionaries, you need to know how to access, update, and add key-value pairs. To access the value for a specific key, use square brackets with the key name, like item_prices["apple"]. If you want to update the price of an existing item, assign a new value to its key. To add a new item, simply assign a value to a new key. These operations make dictionaries flexible for organizing and summarizing paired data in your daily tasks.

1234567
# Update the price of an existing item item_prices["banana"] = 0.69 # Add a new item to the dictionary item_prices["eggs"] = 2.99 print(item_prices)
copy

1. What is a key in a Python dictionary?

2. How do you access the value associated with a key?

3. Fill in the blanks to add a new key-value pair to a dictionary.

question mark

What is a key in a Python dictionary?

Select the correct answer

question mark

How do you access the value associated with a key?

Select the correct answer

question-icon

Fill in the blanks to add a new key-value pair to a dictionary.

=
{'laundry': 'Saturday', 'groceries': 'Sunday'}

Click or drag`n`drop items and fill in the blanks

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 2
some-alt