You can't just convert to a set and back, because sets don't preserve order. Instead, track what you've seen while building a new list. The pattern: Create an empty set to track seen words
Create an empty list for results
For each word: if not seen, add to both the set and the list The set gives you lookup to check if a word is new. The list preserves insertion order.