Title
InfoDb = []
# Append to List a Dictionary of key/values related to a greys anatomy characters
InfoDb.append({
"FirstName": "Meredith",
"LastName": "Grey",
"Specialty": "General Surgery",
"Spouse": "Derek Shepherd",
"Rule violations": ["got sued so many times","dropping liver", "ruining alzheimers trial", "stealing baby", "taking things that aren't her specialty", "ellis greys daughter", "not like other girls"]
})
# Second append to another character
InfoDb.append({
"FirstName": "Cristina",
"LastName": "Yang",
"Specialty": "Cardio",
"Spouse": "Owen Hunt",
"Rule violations": ["killed her bosses husband but otherwise none to speak of"]
})
InfoDb.append({
"FirstName": "Alex",
"LastName": "Karev",
"Specialty": "Peds",
"Spouse": "Izzie Stevens",
"Rule violations": ["mean"]
})
print(InfoDb)
def print_data(d_rec):
print(d_rec["FirstName"], d_rec["LastName"]) # using comma puts space between values
print("\t", "Specialty:", d_rec["Specialty"]) # \t is a tab indent
print("\t", "Spouse:", d_rec["Spouse"])
print("\t", "Rule violations: ", end="") # end="" make sure no return occurs
print(", ".join(d_rec["Rule violations"])) # join allows printing a string list with separator
print()
# for loop iterates on length of InfoDb
def for_loop():
print("For loop output\n")
for record in InfoDb:
print_data(record)
for_loop()
def while_loop():
print("While loop output\n")
i = 0
while i < len(InfoDb):
record = InfoDb[i]
print_data(record)
i += 1
return
while_loop()
def recursive_loop(i):
if i < len(InfoDb):
record = InfoDb[i]
print_data(record)
recursive_loop(i + 1)
return
print("Recursive loop output\n")
recursive_loop(0)
different kinds of loops after adding to the database but all keep repeating until all (3) items in the database are printed or reach maximum printing capacity