Read the question, write Python on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read a line of integers, remove duplicates, and print the remaining values sorted ascending on one line.
This is the two-step combo you reach for constantly: a set to dedupe, then sorted() to make the output stable.
Input. One line: integers separated by spaces.
Output. The distinct values, ascending, space-separated.
Examples
Input
3 1 2 3 1 5
Output
1 2 3 5
Input
4 4 4
Output
4
Hint
- set(nums) keeps one of each value but has no order.
- sorted(set(nums)) fixes the order; print(*result) spaces them out.
Show correct code
Peek only after you have tried. You can still Check your own version.
nums = list(map(int, input().split()))
print(*sorted(set(nums)))
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.