Exercise 13
Write a python algorithm to remove duplicate elements from a list.
Solution
def removeDuplicate(L):
# initializing the list without duplicate elements
unique = []
for x in L:
if x not in unique:
unique.append(x)
return unique
# testing the algorithm
L = [11 , 3 , 11, 3 , 4 , 11 , 7 , 3 , 11]
print(removeDuplicate(L)) # the output is : [11, 3, 4, 7]
Younes Derfoufi
my-courses.net
my-courses.net