--Originally published at Start in the world of the #TC101
A Dictionary is a way to store data just like a list, but instead of using only numbers to get the data, you can use almost anything. This lets you treat a dictionary like it’s a database for storing and organizing data any kind of data. Each key is separated from its value by a colon (:), the items are separated by commas, and the whole thing is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}.
Example:
states = {
“Oregon”: “OR”,
“Florida”: “FL”,
“California”: “CA”,
“New York”: “NY”,
“Michigan”: “MI”
}
print (“Michigan’s abbreviation is: “), print (states[“Michigan”])
print (“Florida’s abbreviation is: “), print (states[“Florida”])
print (“Oregon’s abbreviation is: “), print (states [“Oregon”])
print (“California’s abbreviation is: “), print (states [“California”])
print (“New York’s abbreviation is: “), print (states [“New York”])
↓ ↓ ↓ ↓ ↓ ↓ ↓
Karina-Ramirez:desktop Karina$ python3 dictionary.py
Michigan’s abbreviation is: MI
Florida’s abbreviation is: FL
Oregon’s abbreviation is: OR
California’s abbreviation is: CA
New York’s abbreviation is: NY