Learn Python 3 - Gradebook project error -step 8 .remove

https://www.codecademy.com/courses/learn-python-3/projects/python-gradebook

Hello. I am on step 8 of the gradebook project in Learn Python 3 (removing the Poetry grade of 85 from the gradebook list.

I keep getting an error. I’ve tried searching in the community and google and cannot figure out why I am receiving this error.

Side note - I used the list(zip) option because I found it in the community when I was stuck on a prior step in this same project but this method was never discussed - so I am not sure if it could be part of the issue

I am getting the following error:

Traceback (most recent call last):
File “script.py”, line 26, in
gradebook[2].remove(85)
AttributeError: ‘tuple’ object has no attribute 'remove’

This is my code
last_semester_gradebook = [[“politics”, 80], [“latin”, 96], [“dance”, 97], [“architecture”, 65]]

Your code below:

subjects = [“physics” , “calculus” , “poetry” , “history”]

grades = [98, 97, 85, 88]

gradebook = list(zip(subjects, grades))

gradebook.append([“Computer Science”, 100])

gradebook.append([“Visual arts”, 93])

gradebook[-1][1] = 98

gradebook[2].remove(85)
print(gradebook)

Any help is appreciated. I’ve tried searching in the community and google and cannot figure out why I am receiving this error.

Side note - I used the list(zip) option because I found it in the community when I was stuck on a prior step but this method was never discussed - not sure if it could be part of the issue

When you use the zip() function nested inside a list function-list(zip)), it creates a list of tuples, like so:

a = [1, 2, 3] b = ["A", "B", "C"] print(list(zip(a,b)))

Tuples are immutable, which means they can’t be modified. This includes removing items. That is where your error is coming from.


Note, the exercise wants you to make the two-dimensional list (not list of tuples) without using any methods.

2 Likes

Thank you for the feedback. I went ahead and manually entered the gradebook list but when I attempted to use (step 5) .append to add [“computer science”, 100] to the gradebook list, I still receive an error even though I am using the same format that is shown under Hint.

Any suggestions for this error? I am stuck again.

Traceback (most recent call last):
File “script.py”, line 16, in
gradebook.append([“Computer Science”, 100])
AttributeError: ‘tuple’ object has no attribute 'append’

**

Your code below:

subjects = [“physics” , “calculus” , “poetry” , “history”]

grades = [98, 97, 85, 88]

gradebook = [“physics” , 98], [“calculus” , 97], [“poetry” , 85], [“history” , 88]
print(gradebook)

gradebook.append([“Computer Science”, 100])
print(gradebook)
#gradebook.append([“Visual arts”, 93])

Print(gradebook)**

Since tuples are immutable, you can’t modify them. .append is an example of a method which modifies a list, and thus can’t be used with tuples.

1 Like

But I manually re-entered the grade book list manually instead of the zip option to avoid creating a tuple. Then I thought the .append option would work.

How is this properly done to be able to use the .append option?

To create a nested list, you need to wrap the entire thing in square brackets []:

nested_list = [["list", "1"],["list", "2"],["list", "3"]]

Doing it the way you’re doing it:

nested_item = ["list", "1"], ["list", "2"], ["list", "3"]

Creates a tuple.

2 Likes

Although we can append a tuple. Just saying.

1 Like

As in:

some_list = [1,2,3]
some_list.append(("some", "tuple"))

True, thank you!

1 Like

Even,

>>> some_list = []
>>> some_list.append(('',))
>>> some_list
[('',)]
>>> 
1 Like

Awesome. Cannot believe I overlooked that but thanks again!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.