Hashmaps Hacks
am_album = {
"title": "AM",
"artist": "Artic Monkeys",
"year": 2013,
"genre": ["Indie"],
"tracks": {
1: "Do I Wanna Know",
2: "R U Mine?",
3: "One For The Road",
4: "Arabella",
5: "I Want It All",
6: "No. 1 Party Anthem",
7: "Mad Sounds",
8: "Fireside",
9: "Why'd You Only Call me When You're High",
10: "Snap Out of It",
11: "Knee Socks",
12: "I Wanna Be Yours"
}
}
# Printing the dictionary
print(am_album)
print(am_album['tracks'])
print(am_album['tracks'][6])
am_album["producer"] = ['James Ford, Arctic Monkeys']
# Printing the dictionary
print(am_album)
for k,v in am_album.items(): # iterate using a for loop for key and value
print(str(k) + ": " + str(v))
tracks = am_album["tracks"]
for k, v in tracks.items():
print(str(k) + ": " + str(v))
def search():
search = input("What would you like to know about the album?")
if am_album.get(search.lower()) == None:
print("Invalid Search")
else:
print(am_album.get(search.lower()))
search()
# This is a very basic code segment, how can you improve upon this code?
def research():
search = input("What would you like to know about the album?")
if am_album.get(search.lower()) == None:
print(search, " is an invalid input, try again!")
research()
else:
print(am_album.get(search.lower()))
research()