Solution: Remove All Duplicate Elements
Learn how to remove all duplicate elements in a string, a list, and a tuple.
We'll cover the following...
The solution to the problem of removing all duplicate elements present in a string, list, and tuple is given below.
Solution
Press + to interact
# Delete duplicates from string, list and tuples = 'Razmattaz's = ''.join(sorted(set(s), key = s.index))print(s)lst = ['R', 'a', 'a', 'z', 'm', 'a', 't', 't', 'a', 'z']lst = list(sorted(set(lst), key = lst.index))print(lst)tpl = ('R', 'a', 'a', 'z', 'm', 'a', 't', 't', 'a', 'z')tpl = tuple(sorted(set(tpl), key = tpl.index))print(tpl)
Explanation
- Lines 2–3: