Hi, I’m new to Python. Need help on the following:
How do I use the .remove to remove the value of 85?
gradebook = [[‘physics’, 98], [‘calculus’, 97], [‘poetry’, 85], [‘history’, 88], [‘computerscience’, 100], [‘visual arts’, 98]]
thank you in advance for your help!
mtf
#2
If .remove()
is a list method, then it can be applied to nested lists, as well. So zero in on the nested list, and apply the method to that one.
>>> gradebook = [['physics', 98], ['calculus', 97], ['poetry', 85], ['history', 88], ['computerscience', 100], ['visual arts', 98]]
>>> nested_list = gradebook[2]
>>> nested_list.remove(85)
>>> print (gradebook)
[['physics', 98], ['calculus', 97], ['poetry'], ['history', 88], ['computerscience', 100], ['visual arts', 98]]
>>>
1 Like
thank you so much!! I learnt something new today!
1 Like