01 / 07
When you want the duplicates gone
Sometimes you want the repeats taken out of a list. Survey answers, the items on an order, the names of the people who turned up.
You can already write it. Set up an empty list and add only the things that are not in it yet.
But that is four lines for nothing more than "drop the duplicates".
numbers = [3, 1, 3, 2, 1]kinds = []for n in numbers: if n not in kinds: kinds.append(n)print(kinds)Result
[3, 1, 2]