I guys, i’m working on a script, but i’ve problem on removing double value in a list,
the list is formatted in this way: a = [(x,y),(k,j),…] ans so on,
the thing i want to do is to remove the repeated value starting from the end of the list, i want to do this because, virtually, each element have an index(a[i]) that i use for vertex so i’ can’t lost the the value at that index.
so i need to remove double from the end to the start of the list. there is a way to do this???
That was my first thought too, however, converting a list to a set and back again does not maintain the order of the elements. If the order doesn’t matter then that way works fine.
hi guys, thanks for reply!! but sephiroth give me the inspiration, and i think i’ve solved the problem. the code of sephiroth, remove double , but if there are more then two repeat it dont see it, and it don’t remove from the end to the first.
so this is the code i used:
a.reverse()
for item in a:
while a.count(item) >1:
a.remove(item)
a.reverse()
the explanation:
a.reverse invert the list so i can remove the last element by first.
then i substitute “if” with “while” (it works i don’t know why ;P)