# # Nested data structures. # # Each item in score_1 contains the scores of three homework assignments. scores_1 = [ [96, 89, 97], [88, 84, 83], [64, 57, 72] ] print(""" # Each item in score_1 is the score of three homework assignments. scores_1 = [ [96, 89, 97], [88, 84, 83], [64, 57, 72] ] """) # print the individual scores of each student. for item in scores_1: print(f"student score: ", end="") for score in item: print(score, end=" ") print() print() # putting a comma between scores. for item in scores_1: print(f"student scores: ", end="") for pos, score in enumerate(item): if pos == len(item)-1: print(score) else: print(f"{score}, ", end="") print() # Second version using list comprehensions. for item in scores_1: print(f"student scores: ", end="") str_item = [str(score) for score in item] print(", ".join(str_item)) print() # add student # for student_num, item in enumerate(scores_1): print(f"student #{student_num + 1} scores: ", end="") for pos, score in enumerate(item): if pos == len(item)-1: print(score) else: print(f"{score}, ", end="") # Each item in score_2 contains a dict with the name of the student as the key and the scores of three homework assignments as the value. scores_2 = { "Joe": [96, 89, 97], "Jane": [88, 84, 83], "Jenny": [64, 57, 72] } print() for student in scores_2.keys(): print(f"{student}'s scores: ", end="") for pos, score in enumerate(scores_2[student]): if pos == len(item)-1: print(score) else: print(f"{score}, ", end="") scores_3 = { "Joe": {"HW1": 96, "HW2": 89, "HW3": 97, "HW4": 84}, "Jane": {"HW1": 88, "HW2": 84, "HW3": 83}, "Jenny": {"HW1": 64, "HW2": 57, "HW4": 72} } print() for student in scores_3.keys(): print(f"current student: {student}") print(f"{student}'s scores: ", end="") print(f"scores_3[student]: {scores_3[student]}") print(f"scores_3[student.keys() {scores_3[student].keys()}") for pos, assignment_name in enumerate(scores_3[student].keys()): print(f"student/assignment: {student}/{assignment_name}") if pos == len(scores_3[student].keys())-1: print(f"{assignment_name}: {scores_3[student][assignment_name]}") else: print(f"{assignment_name}: {scores_3[student][assignment_name]}, ", end="")