What is a Dictionary?
Part of the Logic & Flow section of Coddy's Python journey — lesson 7 of 78.
A dictionary in Python is a collection of data that stores data in key-value pairs. Unlike lists, which use indices to access elements, dictionaries use keys. Each key in a dictionary must be unique, and it is associated with a value.
Think of a real-world dictionary. You look up a word (the key) to find its meaning (the value).
In Python, a dictionary works similarly. For example, you can have a dictionary where the keys are names of countries and the values are their capitals.
Dictionaries are useful when you have data that is naturally paired together and when you need to quickly access a value by knowing its associated key.
Cheat sheet
A dictionary stores data in key-value pairs. Each key must be unique and is used to access its associated value.
Dictionaries are useful for naturally paired data and when you need quick access to values by their keys.
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Logic & Flow
1Variables Exploration
ConstantsMultiple Variable AssignmentsSwapping VariablesPlaceholder VariablesRound NumbersList Casting4Contact Book Application
Display MenuAdd Contact7Sets Part 2
Mathematical Operations Part 1Mathematical Operations Part 2Recap - Treasure HuntSubsets and SupersetsIterating Over SetsRecap - Tournament Tracker2Dictionaries Part 1
What is a Dictionary?Creating a DictionaryAccessing ValuesModifying DictionariesRecap - Recipe Manager5Advanced Decision Making
Ternary OperatorMembership ChecksIdentity ChecksIndentation ErrorsRecap - Vacation Filter8Student Records Manager
Project OverviewAdd Student11Advanced Functions
Returning Multiple ValuesLambda Functions Part 1Lambda Functions Part 2Recap Challenge - Lambda SortRecursive Functions Part 1Recursive Functions Part 2Recap - Sum Nested List14Higher-Order Functions
The Map FunctionThe Filter FunctionRecap - Email ValidatorRecap - Number Processor3Dictionaries Part 2
Dictionary MethodsNested DictionariesChecking for KeysLooping Through DictionariesRecap - Frequency Counter9Advanced Data Aggregation
Using SumFinding Minimum and MaximumSorting Data EfficientlyRecap - Dictionary Sorter