1
Guys I have this list:
lista = [['10616558', 0],
['2856466', 1],
['9715350', 2],
['9715350', 3],
['9715350', 4],
['10720706', 5]]
The first element is any string, and the second is an index. I need to do a function that takes elements from the list that contains the same string, preserving the index.
The output would that way:
>>> lista = removeigual(lista)
>>> lista
[['10616558', 0],
['2856466', 1],
['9715350', 2],
['10720706', 5]]
I have a function that removes duplicates but is only for simple lists, but I could not adapt to my problem:
def removeDuplicates(listofElements):
uniqueList = []
for elem in listofElements:
if elem not in uniqueList:
uniqueList.append(elem)
return uniqueList
The index of the first occurrence of the value must be preserved?
– Woss
That question is answered here.
– TryAgain
Hi Anderson. Yes I need to preserve the indexes!
– Pingam
@Tryagain, the cited problem function works only for simple lists. When I play my list. He returns the same thing to me because of the ratings. It sees the input and sees that it is a different value, and does not remove anything, even though the string has the same value. :/
– Pingam