0

I was trying to write a function that accepts a list of integers as the parameter and then returns the list back with only positive integers (in the same order they were before) but I keep getting an index error.

def filter_positive_list(raw_data):
    le=len(raw_data)
    for i in range(le):
        if raw_data[i]<0:
            raw_data.pop(i)
        else:
            pass
data = [-3, -2, -1, 0, 1, 2, 3]
filter_positive_list(data)
print(data)
khelwood
  • 55,782
  • 14
  • 81
  • 108

0 Answers0