Exercise 9 · Chapter: ListsOptional+50 XP
Fix the Sort
This code has a list of numbers, but they're stored as strings. When you sort strings, they get sorted alphabetically instead of numerically, so "10" comes before "2" (because "1" comes before "2" in the alphabet).
Fix the code so the numbers sort correctly from smallest to biggest.
Hint: You need to convert the strings to integers before sorting!
Expected output
2 5 10 30
Need a hint?
3 available · costs 5 XP each
python
numbers = ["10", "2", "30", "5"]
numbers.sort()
for n in numbers:
print(n)
Output
Run your code to see the output here.