Guidelines

Managing Structured Data with Dictionaries

A dictionary is a data structure that efficiently manages and retrieves data by storing it as pairs of keys and values.

Dictionary Structure
dictionary = { "key1": "value1", "key2": "value2", "key3": "value3", }

For example, you can define a dictionary to store a person's information as follows:

Dictionary Storing Person's Information
person = { "name": "John", "age": 30, "job": "Developer" }

In the code above, the person dictionary contains keys like name, age, and job, with their corresponding values.


What are the Features of a Dictionary?

Dictionaries have the following features:

  1. Fast Lookup: Dictionaries store data as key-value pairs, allowing very fast retrieval of values by their keys.

  2. No Index-based Access: Dictionaries are unordered data structures, so you cannot access elements using an index as you can with lists or tuples.

  3. Unique Keys: Each key in a dictionary must be unique; duplicate keys are not allowed within the same dictionary.


How to Declare a Dictionary?

Dictionaries are defined using curly braces {}, with keys and values connected by a colon :.

Example of Dictionary Declaration
# Declaring an empty dictionary empty_dict = {} # Declaring a dictionary with key-value pairs product = { "name": "Orange", "price": 1000, "best_before": "2024-12-31" }
Mission
0 / 1

What is the most appropriate answer to fill in the blank below?

A dictionary has the characteristic of .
index-based search
fast search
slow search
dynamic search

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result