What I wanted to do was to search in a list and remove a value .
So I wrote the following code
for x in range(10):
if x in list1:
list1.remove(x)
Does this function of order ~ (n^2) since first it looks for the value and then it deletes and pushes the rest of the values backwards ??
Also is there a way to turn this in order n by using try/except
try:
for x in range(10):
list1.remove(x)
except ValueError:
# make it go back to next iteration
This sounds like a job for
filter():Update: one more example where I construct a list using list comprehension: