Question about zip command output using phython

Why does my output look like this [(‘physics’,), (‘calculus’,), (‘poetry’,), (‘history’,), (‘computer science’,), (98,), (97,), (85,), (88,), (100,), ‘visual arts’, 93, (‘politics’, 80), (‘latin’, 96), (‘dance’, 97), (‘architecture’, 65)]

When it is suppose to look like this [(98, ‘physics’), (97, ‘calculus’), (85, ‘poetry’), (88, ‘history’), (‘visual arts’, 93)]

Here is my code:
last_semester_gradebook = [(“politics”, 80), (“latin”, 96), (“dance”, 97), (“architecture”, 65)]

subjects = [‘physics’, ‘calculus’, ‘poetry’, ‘history’]
grades = [98, 97, 85, 88]
subjects.append(‘computer science’)
grades.append(100)
gradebook = list(zip(subjects + grades))
gradebook.append(‘visual arts’)
gradebook.append(93)

full_gradebook = gradebook + last_semester_gradebook;
print(full_gradebook)

zip is a function that takes two arguments, e.g. zip(a, b). a + b will not do what you expect. I’d also be careful with the appends as they won’t be stored in the same way as the other outputs from zip. You’ll probably see this with print.

1 Like