+ 2

Sort

How do I make it so it sorts an integer https://code.sololearn.com/cBE6vdfIAFwq/?ref=app

4th Feb 2022, 12:24 AM
Junior
Junior - avatar
6 Answers
+ 3
So, if your input is all on one line seperated by a space, as shown, then you can split() the input into a list of number strings. You can then map this list using the int function to convert the strings to numbers. Then convert back the map object back to a list, so you now have a list of the numbers that were input as integers instead of strings. Then you can sort() as before. sorter = list(map(int, input().split())) sorter.sort() print(sorter)
4th Feb 2022, 1:35 AM
ChaoticDawg
ChaoticDawg - avatar
+ 4
What do you want ask properly there is no list of variable to short and also 1 string or int can't sort.
4th Feb 2022, 12:34 AM
Abu Habban
Abu Habban - avatar
+ 1
This question is a bit vague. Please describe better what you are trying to accomplish. Give examples of the input(s) the expected action(s) and an example of the expected output(s).
4th Feb 2022, 12:50 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Thanks! ChaoticDawg
4th Feb 2022, 1:37 AM
Junior
Junior - avatar
0
I want it so when I type in multiple numbers like “1 3 5 2” it sorts it so it is now “1 2 3 5” ChaoticDawg and Abu Habban
4th Feb 2022, 1:22 AM
Junior
Junior - avatar