toc: true layout: post categories: [week 2]

title: 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)
[{'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']}, {'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']}]
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()
For loop output

Noor Grewal
	 Residence: 4S Ranch
	 Birthday: October 27
	 Dogs: Luna, Kahlua, Daisy
	 Cats: Merlot, Smeagol
	 Favorite Songs: ['Wasting Love - Iron Maiden', 'Tear - The Smashing Pumpkins', 'Everlong - Foo Fighters']
Sanika Shahapurkar
	 Residence: Del Sur
	 Birthday: September 29
	 Dogs: Striver
	 Cats: none:(
	 Favorite Songs: ['Someone New - Hozier', 'Marvelous - Wallows', 'Saggitarius Superstar - Coin & Faye Webster']