Professional Documents
Culture Documents
CHAPTER 6: DICTIONARY
DICTIONARY
can store an almost limitless amount of information
A dictionary in Python is a collection of key-
value pairs. Each key is connected to a value, and
you can use a key to access the value associated
with that key. A key’s value can be a number, a
string, a list, or even another dictionary.
In fact, you can use any object that you
can create in Python as a value in a
dictionary.
KEY : VALUE
DICTIONARY
can store an almost limitless amount of information
A dictionary in Python is a collection of key-
value pairs. Each key is connected to a value, and
you can use a key to access the value associated
with that key. A key’s value can be a number, a
string, a list, or even another dictionary.
In fact, you can use any object that you
can create in Python as a value in a You can list chess moves. You can list your
dictionary.
favorite
motorcycles.
A List in a Dictionary
02 Listing items inside a Dictionary
Dictionary in a
03 Dictionary
Creating Dictionary inside another
Dictionary
1ST TOPIC:
A List of
Dictionaries
Dictionary
ICYMI: * If the slice looks like this ([ 5 : ]), Python returns all items
from the sixth item through the end of the list.
We print the length of the list to
prove we’ve actually generated
an army of Man-eating Fried
Chicken.
In our program, there would be time where it changes
its variant. Hence, we can use a for loop and an if
statement to change the variant of this chicken.
we use the variable name animes to hold each value from the
dictionary
Inside the main dictionary loop, we use another for loop to
run through each person’s list of favorite animes.
A
Dictionar
y in a
Dictionar
y
3RD
TOPIC:
GENTLE REMINDER:
Nesting a Dictionary in a Dictionary is actually quite
complex if and only if you’re not paying much attention on
your coding.
Here, we start with an actual data from our fellas and the
following are their responses.