0
Remove duplicate items from list
how to Remove duplicate items from list and leave only one items from every duplicated: ex : a = [1,1,1,2,2,2,3,3,3] result = [1,2,3]
5 Respostas
+ 6
#You can also do like this
a = [1,6,1,4,6,9,1,6,9,1]
uniq = []
for i in a:
if i not in uniq:
uniq.append(i)
print(uniq)
+ 5
set sorts the list and can only hold a value once so duplicates are removed. If you wish to maintain the original order, this can be used.
https://code.sololearn.com/cdXh680icSEt
+ 2
# Convert to a set and back into a list.
num= set(a)
result = list(num)
print(result)
+ 2
sets have only unique elements
0
why when convert to set duplicated remove ?