0

how to get duplicates out of list

26th Oct 2016, 2:57 AM
alex slater
alex slater - avatar
4 Respuestas
+ 3
Try this my_list = [3, 5, 2, 1, 4, 4, 1] my_list.sort() for i in range(0,len(my_list)-1): if my_list[i] == my_list[i+1]: print (str(my_list[i]) + ' is a duplicate')
26th Oct 2016, 6:49 AM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 1
You are welcome
26th Oct 2016, 6:53 AM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
0
thank you
26th Oct 2016, 6:50 AM
alex slater
alex slater - avatar
0
you can transform your list into set - a collection that doesn't have duplicates, and then transform it back to a list simply and one-line: myList = list(set(myList))
29th Oct 2016, 10:40 PM
Demeth
Demeth - avatar