a=[] n= int(input("Enter the number of elements in list:")) for x in range(0,n): element=int(input("Enter element" + str(x+1) + ":")) a.append(element) b = set() unique = [] for x in a: if x not in b: unique.append(x) b.add(x) print("Non-duplicate items:") print(unique)
The easiest way is to convert the list into a set and back into a list, since values in a set are unique by definition.
Example:
foo = [1,1,2,3,4,4,5]print('before: ', foo)foo = list(set(foo))print('after: ', foo)