python filter list remove duplicates code example

Example 1: python remove duplicates from list

mylist = ["a", "b", "b", "c", "a"]
mylist = sorted(set(mylist))
print(mylist)

Example 2: sort and remove duplicates list python

myList = sorted(set(myList))

Example 3: remove duplicates in sorted array python

j = 0

// traverse elements of arr
for i=0 to n-2
    // if ith element is not equal to (i+1)th element of arr, then store ith value in arr[j]
    if arr[i] != arr[i+1]
        arr[j] = arr[i]
        j += 1

// store last value of arr in temp
arr[j] = arr[n-1]
j += 1

// print first j elements of array arr
for i=0 to j-1 
    print arr[i]

Tags:

Java Example