Question about execise "Flow, Data, and Iteration - Python Gradebook"

Why is it when I list(zip) between last_semester_gradebook and gradebook, it doesn’t include the appends that i added to the lists in the output and only include the items that were already in the subjects and grades lists?
it adds the appends only when i do:
full_grade_book = gradebook +last_semester_gradebook

when i want to do:
full_gradebook = list(zip(last_semester_gradebook,gradebook))

zip() will include any appends you make until you actually go through the zip() object (via list(obj) or for-in or otherwise) one time, but after that it will be exhausted, and you will need to instantiate a new zip() object.

1 Like


so i have created one zip as below, but still get message error
Traceback (most recent call last):
File “”, line 7, in
full_grade_book = gradebook +last_semester_gradebook
TypeError: can only concatenate list (not “str”) to list

last_semester_gradebook = [(“politics”, 80), (“latin”, 96), (“dance”, 97), (“architecture”, 65)]
subjects = [“physics”, “calculus”, “poetry”, “history”]
grades = [98, 97, 85, 88]
gradebook = list(zip(grades, subjects))
print (list(gradebook ))
last_semester_gradebook =“full_gradebook”
full_grade_book = gradebook +last_semester_gradebook
full_grade_book = list(zip(gradebook ,last_semester_gradebook))
print (list(full_grade_book))

“full_grade_book = gradebook +last_semester_gradebook”–> not sure what happen to this also I follow the instruction, could someone answer?

thank you

First, and always foremost: read the error message!

full_grade_book = gradebook +last_semester_gradebook
TypeError: can only concatenate list (not “str”) to list

Well, it is telling you right there that you are trying to concatenate (i.e., use the + operator) a string to a list. So that means that either gradebook is a list and last_semester_gradebook is a string or vice versa.

And, right here:

last_semester_gradebook = “full_gradebook”

… you have assigned a string, ‘full gradebook’ to the variable last_semester_gradebook .

Comment out that line, and run it again.

So i’ve managed to complete this task - but i’m curious on how i would be able to put a line between the list from last_semester_gradebook and gradebook


There are a number of options, the simplest being to iterate over full_gradebook and print each item with a line between them. We could also just print the two items that in the full_gradebook by their own names.

i’m not sure if i’ve written the wrong question or I just don’t understand the answer - i am a bit of a newb here!

What I’m trying to print is
{the contents of gradebook}
{a line break}
{the contents of last_semester_gradebook

so what code would make the console print each list but with a line break separating the displayy

print ('something')
print ()
print ('something else')