Python Gradebook exercise question

full_gradebook = list(gradebook) + last_semester_gradebook


why does it need the list function in the full_gradebook? You have already returned the answer to the variable. Why does the variable then need the List() function?
Not really sure what to call function()

Did you try it without the list() function?

last_semester_gradebook is a list of tuples. gradebook is a zip object. To attempt to combine it with a list will raise an error:

full_gradebook = last_semester_gradebook + gradebook

Traceback (most recent call last):
  File "", line 21, in <module>
    full_gradebook = last_semester_gradebook + gradebook
TypeError: can only concatenate list (not "zip") to list

The list() function (technically, it’s not a function, but a class; invoking it returns an instance of the class) reads the data in the zip object and returns it as a list, which you can then concatenate with another list.

yes, i tried it without the list() class. It gave the “can only concatenate” zip error. That’s what gave me the clue on how to resolve it.

1 Like

OK well, reviewing the assignment, it depends upon what is assigned to the variable gradebook. If it is the zip object, you need to cast it to type list before concatenating with the list, last_semester_gradebook. If it is already a list (as suggested in step 3), then of course, you do not.

To me, the exercise is pretty ambiguous about it, but it seems that you have a good understanding of what ultimately must be done.

thanks. nuts and bolts. not elegant, but works.
Thanks for taking the time to help.