I wrote an algorithm that shall print a number in a sequence that is NOT redundant.
My algo:
o = [2,3,4,5,2,4,5]
for x in o:
print(x)
o.remove(x)
if x not in o:
print("NOT REDUNDANT" + str(x))
out:
2
4
2
NOT REDUNDANT 2
5
Where the heck is the output of the 3 at index two of the list?
If I add an o.sort() right under the initialization of o I get the correct output:
o = [2,3,4,5,2,4,5]
o.sort()
for x in o:
print(x)
o.remove(x)
if x not in o:
print("NOT REDUNDANT" + str(x))
out:
2
3
NOT REDUNDANT 3
4
5
Can someone explain why the sort is necessary?