1mylist = ["a", "b", "b", "c", "a"]
2mylist = sorted(set(mylist))
3print(mylist)
1
2 mylist = ["a", "b", "a", "c", "c"]
3mylist = list(dict.fromkeys(mylist))
4
5 print(mylist)
1# HOW TO REMOVE DUPLICATES FROM A LIST:
2# 1) CREATE A LIST
3my_list = [1, 2, 3, 4, 5, 5, 5, 1]
4# 2) CONVERT IT TO A SET AND THEN BACK INTO A LIST
5my_list = list(set(my_list))
6# 3) DONE!
7print(my_list) #WILL PRINT: [1, 2, 3, 4, 5]
1# remove duplicate from given_list using list comprehension
2res = []
3[res.append(x) for x in given_list if x not in res]
1# removing duplicated from the list using naive methods
2
3# initializing list
4sam_list = [11, 13, 15, 16, 13, 15, 16, 11]
5print ("The list is: " + str(sam_list))
6
7# remove duplicated from list
8result = []
9for i in sam_list:
10 if i not in result:
11 result.append(i)
12
13# printing list after removal
14print ("The list after removing duplicates : " + str(result))
15
1 ArrayList<Object> withDuplicateValues;
2 HashSet<Object> withUniqueValue = new HashSet<>(withDuplicateValues);
3
4 withDuplicateValues.clear();
5 withDuplicateValues.addAll(withUniqueValue);