Answer the question
In order to leave comments, you need to log in
Python. Iterating over unique values skips values?
Iteration skips 'two' as unique (even though it's not in the checklist) and leaves it for later
def list(lst):
lst_new = []
while lst:
lst_temp = []
for i in lst:
if i not in lst_temp:
lst_temp.append(i)
lst.remove(i)
lst_new += lst_temp
return lst_new
l = list(["one", "one", "two", "two", "three", "three", "four", "one"])
d = ["one", "two", "three", "four", "one", "two", "three", "one"] #должно быть так
print(l)
print(d)
Answer the question
In order to leave comments, you need to log in
Because it is not necessary to change the iterable collection.
You read the list and change it at the same time.
In general, you have a strange design.
Do not use names that are the same as built-in types.
Changing the iterated list is also a bad idea, when an element is removed, the remaining elements change their position, but the loop takes the next element, regardless of whether the order has changed or not, that's why there are gaps.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question