← Back to Data Structures & Algorithms
Question 537
Remove Duplicates Keep Order
Remove Duplicates Keep Order
Write remove_duplicates_keep_order(values: list[int]) -> list[int] that returns a new list holding each value once, in the order of its first appearance. Walk the list once, keep a set of the values already added (its add() method records one), and append() a value to the result only when it is not yet in the set. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line of space-separated integers (possibly empty); the tests print the list your function returns.
Expected Output:
[3, 1, 2]= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Data Structures & Algorithms
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.