-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictionaries.py
28 lines (25 loc) · 925 Bytes
/
dictionaries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# -------------------------------------------------------------------------------------------
# Dictionaries
# special structure in py which allows us to store info in key value pairs
# the key must be unique
monthConversions = {
"Jan": "January",
"Feb": "February",
"Mar": "March",
"Apr": "April",
"May": "May",
"Jun": "June",
"Jul": "July",
"Aug": "August",
"Sep": "September",
"Oct": "October",
"Nov": "November",
"Dec": "December",
}
print(monthConversions["Oct"])
print(monthConversions.get("Oct")) #get can also be used to access the definition using key
print(monthConversions.get("Dsa", "Not a valid key")) #As this key isnt present, the get function will print "Not a valid key"
# OUTPUT: October
# October
# Not a valid key
# ------------------------------------------------------------------------------------------------------------