question: Complete the function remove number such
that given a list of integers and an integer n, the function
removes every instance of
n from the list. Remember that this function needs to modify the
list, not return a new list.
please edit the Python form without errors
def remove_number(lst: List[int], number: int) ->
None:
"""
Remove every instance of
number in lst. Do this
*in-place*, i.e.
*modify* the list. Do NOT
return a new list.
>>> lst = [1, 2, 3]
>>> remove_number(lst, 3)
>>> lst
[1, 2]
"""
pass
To remove all the instances of a number from the list, traverse the list using for loop.
Compare each element with the number that has to be removed from the list. If the element matches the number, remove that element from the list.
The function remove_number is defined as follows:
def remove_number(lst,number):
#remove all occurrences of the number
for i in lst:
if(i == number):
lst.remove(i)
Creation of the list and call the function remove_number()
Complete code snippet with output:
Get Answers For Free
Most questions answered within 1 hours.