Practicing with Lists and Dictionaries
InfoDb = []
# Append to List a Dictionary of key/values
InfoDb.append({
"FirstName": "Noor",
"LastName": "Grewal",
"DOB": "October 27",
"Residence": "4S ranch",
"Email": "noorkg05@gmail.com",
"Car": "2012-Mazda CX9",
"Owns Dogs": ["Luna", "Kahlua", "Daisy"],
"Owns Cats": ["Merlot", "Smeagol"],
"Favorite Songs": ["Wasting Love - Iron Maiden", "Tear - The Smashing Pumpkins", "Everlong - Foo Fighters"]
})
# Append to List a 2nd Dictionary of key/values
InfoDb.append({
"FirstName": "Sanika",
"LastName": "Shahapurkar",
"DOB": "September 29",
"Residence": "Del Sur",
"Email": "sanika.shahapurkar@gmail.com",
"Car": "2018-BMW 430i",
"Owns Dogs": ["Striver"],
"Owns Cats": ["none:("],
"Favorite Songs": ["Someone New - Hozier", "Marvelous - Wallows", "Saggitarius Superstar - Coin & Faye Webster"]
})
# Print the data structure
print(InfoDb)
def print_data(d_rec):
print(d_rec["FirstName"], d_rec["LastName"])
print("\t", "Residence:", d_rec["Residence"])
print("\t", "Birthday:", d_rec["DOB"])
print("\t", "Dogs: ", end="")
print(", ".join(d_rec["Owns Dogs"]))
print("\t", "Cats: ", end="")
print(", ".join(d_rec["Owns Cats"]))
print("\t", "Favorite Songs:", d_rec["Favorite Songs"])
# for loop iterates on length of InfoDb
def for_loop():
print("For loop output\n")
for record in InfoDb:
print_data(record)
for_loop()