AttributeError: 'zip' object has no attribute 'append'

https://www.codecademy.com/paths/computer-science/tracks/cspath-flow-data-iteration/modules/dspath-lists/projects/gradebook

My question is from the python gradebook project. " Your grade for visual arts just came in! You got a 93! After the creation of gradebook (but before you print it out), use append to add ("visual arts", 93) to gradebook " is task #6. Below is the code I have so far:

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 = zip(subjects, grades)
gradebook.append((“visual arts”, 93))

However, when I run it i get the error “AttributeError: ‘zip’ object has no attribute ‘append’”. I looked it up and apparently on python 3 the zip() turns it into a zip object and not a list, any ideas on how I can get this to work?

14 Likes

Nevermind I figured it out lol

gradebook = list(zip(subjects, grades)

Was able to fix it by turning it into a list, that way the append.() will work

37 Likes

@beta9196990428 Thanks for that info. I searched the web but couldn’t find append relating to zip.

Thank you so much for posting this. Was driving me nuts!

I didn’t understand why do we need to write this was…Could anybody please explain…Thanks

.append() is a list method, zip() does not return a list.

3 Likes

Thank you, I was not able to figure it out :blush: sometimes I feel really useless.

Thank you. I wouldn’t be able to figure it out myself.

super helpful! thanks for posting

yeah same thing faced me thanks for the help

Hi! Now that I’ve figured that out i keep getting a syntax error for that line even though I’ve literally copied it down exactly as the hint gives me! I don’t understand what the heck is wrong

gradebook = list(zip(subjects, grades)
gradebook.append((“visual arts”, 93))

File “script.py”, line 15
gradebook.append((“visual arts”, 93))
^
SyntaxError: invalid syntax
WHYYYYY :frowning:

When dealing with syntax error, and especially the kind at the start of a line, also check the line above to ensure you closed everything off properly.

2 Likes