educative.io

A simpler for loop for the challenge

def remove_even(lst):

“”“remove even numbers from list”""

for item in lst.copy():

if item % 2 == 0:

  lst.remove(item)

return lst

print(remove_even([2,1,2,4,5,10,6,3,9,11,12,99]))


Course: Educative: Interactive Courses for Software Developers
Lesson: Educative: Interactive Courses for Software Developers

Hello @Marcelo_Goes_de_Frei,
The solution you are providing has a time complexity of O(n^2) because the python list.remove has a complexity of O(n). So, the nested loop gives us an end result of O(n^2). If we just talk about the validity hen yes your solution would work as well.
Hope this helps