Python bootcamp · Lab 35

Sort a list

mediumSort Lists10 minLesson: Sort Lists

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 and print them sorted ascending, space-separated.

sorted() returns a new list. list.sort() edits in place. Either is fine here.

Input. One line: integers separated by spaces.

Output. The same values, ascending, space-separated.

Examples

Example 1
Input
5 3 1 4 2
Output
1 2 3 4 5
Example 2
Input
3 3 1
Output
1 3 3
Hint
  1. print(*sorted(nums))
  2. Negatives sort before positives in Python.
Show correct code

Peek only after you have tried. You can still Check your own version.

nums = list(map(int, input().split()))
print(*sorted(nums))
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.