Deviopath › Python

Remove Duplicates, Keep Order

Easy · Lists

Turning a list into a set removes duplicates but loses the order. To keep the order, walk the list and remember what you have already seen in a set. Bonus: dict keys keep insertion order, so dict.fromkeys(items) also works.

Write a function dedupe(items) that returns a new list without duplicates, keeping the first occurrence of each item in its original position.

Next: Word Count