I'm trying to do a function which deletes the negative numbers from a list that given externally and returns the new list. But my code gives me "IndexError: list index out of range" error. How can I fix it?
class Prtc:
def __init__(self, x, _lst):
self.x = x
self._lst = _lst
def del_neg(self, _lst):
i = 0
while i < len(_lst):
if _lst[i] < 0:
_lst.remove(i)
i += 1
return _lst