Hi,

Working thru the Gradebook coding challenge and struggling with #8 (You decided to switch from a numerical grade value to a Pass/Fail option for your poetry class. Find the grade value in your `gradebook` for your poetry class and use the `.remove()` method to delete it).
Thought I had a grasp on the use of “remove”, but turns out that is wrong.

My current code for gradebook is gradebook is gradebook = [[“physics”, 98], [“calculus”, 97], [“poetry”, 85], [“history”, 88]].

Output is “[[‘physics’, 98], [‘calculus’, 97], [‘poetry’, 85], [‘history’, 88], [‘computer science’, 100], [‘visual arts’, 98]]” as computer science and Visual arts have both been added.

To remove the Poetry score, shouldn’t the following work: “gradebook.remove[2][1]”?

Certainly possible I am way off though. As of two weeks I had never coded, so please have mercy…

Thanks, Ted

`.remove` does not work that way (and you would need the argument for the function between `(` and `)` instead of between `[` and `]`

If you have this list: `listA = ['a', 'b', 'c', 'd']`
and you want to remove `'c'` (which is at index 2)
you would do `listA.remove('c')`

It’s more complicated with a list of lists (a 2D list)
`listB = [ ['a', 'b', 'c', 'd'], ['x', 'y', 'z'] ]`
If I want to remove `'c'`, I first have to access the list that contains it;
the list that contains `'c'` is an element of `listB` ;
the list that contains `'c'` is the first element of `listB`, so its at an index of `0` for `listB`
Therefore the list that contains `'c'` is `listB[0]` .
I’d remove `'c'` from this list by doing `listB.remove('c')` .

Similarly, the list containing ‘poetry’ is `gradebook[2]`
which is `["poetry", 85]`
so to remove the `85`, you would do
`gradebook[2].remove(85)`

Thank you very much for the response. That does make sense, and resolved the issue.

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