Stuck with Gradebook

Can’t remove “poetry” using .remove

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 = [[“physics”, 98], [“calculus”, 97], [“poetry”, 85], [“history”, 88]]

gradebook.remove(2)

gradebook.append ([“computer science”, 100])

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

gradebook[-1][-1] = 98

print(gradebook)

post your code with 3 triple backticks, ``` ,at the start and end for better presentation

Thanks

This is the issue right here:
gradebook.remove(2)

You’re missing something.

Yes, when I write:
gradebook.remove(2)
it shows an error

I can delete it only with
gradebook.remove([“poetry”, 85])

You didn’t specify an index in gradebook and the .remove() method isn’t being used correctly.

How it should be written?

Did you look at the hint by any chance?

You’re removing an item from a sublist…So, you can’t just pass (85) through as an argument. You have to identify the index of the sublist first.

If you just had a list, then yes, this would work:

grades = [99, 85, 76, 49]
grades.remove(85)
print(grades)

But, you have a list inside a list.

Thank you, everything is okay now

1 Like