Python List and Dictionaries
List and Dictionary
print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
name = "Lydia Cho"
print("name", name, type(name))
print()
print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
age = 16
print("age", age, type(age))
print()
print("What is variable name/key?", "value?", "type?", "primitive or collection?")
print("What is different about the list output?")
langs = ["Python", "JavaScript", "Java"]
print("langs", langs, type(langs), "length", len(langs))
print("- langs[0]", langs[0], type(langs[0]))
print()
InfoDb = []
InfoDb.append({
"FirstName": "Lydia",
"LastName": "Cho",
"DOB": "April 12",
"Residence": "San Diego",
"Email": "lydiac55288@stu.powayusd.com"
})
print(InfoDb)
def print_data(d_rec):
print(d_rec["FirstName"], d_rec["LastName"])
print("\t", "Residence:", d_rec["Residence"])
print("\t", "Birth Day:", d_rec["DOB"])
print()
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()
FirstName = input("What is your first name?")
FavoriteBread = input("What is your favorite bread?")
FavoriteColor = input("What is your favorite color?")
print(FirstName)
print(FavoriteBread)
print(FavoriteColor)
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)
print("Nested Loop")
for i in range(1, 6):
for j in range(1, 6):
print(i * j, end=' ')
print()