Question:
With a given list [5,3,5,3,6,8,3,1,9,4,5,9,0,7], write a program to print this list after removing all duplicate values with original order reserved.
Program:
1 2 3 4 5 6 7 8 9 10 11 12 |
<strong>def removeD</strong>uplicate( li ): newli=[] seen = set() for item in li: if item not in seen: seen.add( item ) newli.append(item) return newli li=[5,3,5,3,6,8,3,1,9,4,5,9,0,7] print (removeDuplicate(li)) |
Explanation:
Set() function stores number of values without duplicate.
Output:
1 |
[5, 3, 6, 8, 1, 9, 4, 0, 7] |
Leave a Reply