Gradebook

I’m getting a discrepancy with zip vs + concatenation:
When I use + everything works fine.
When I use zip I lose all the information I appended to the -gradebook-

Is there a logical explanation for this? I thought zip and + would produce the same result.

image

image
image

image
image

.zip() and list concatenation (+) are two very different things.

.zip() allows us to loop over multiple lists at the same time:

for subject, grade in zip(subjects, grades):
   print(subject, grade)

for list concatenation/extending i am going to refer you to some documentation:

https://blog.usejournal.com/concatenating-two-lists-in-python-3cf9051da17f

2 Likes

I see! So, when we are applying zip() to subjects and grades we are actually looping over the two lists to combine the grade with the subject not actually doing a concatenation of the lists!
So the zip function actually worked. Just not what we wanted.
It created nested tuples.
image

Got it!

Thank you!

2 Likes