Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to sort 10 integers in python?

I am a novice programmer and have been struggling with some simple problems for too long

The pictures are sample details
1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Assuming you’re taking user (keyboard) input, then you could do this:

indata = input('Enter some integers separated by space: ')
print(*sorted(map(int, indata.split())), sep='\n')

Output:

Enter some integers separated by space: 4 85 3 234 45 345 345 122 30 12
3
4
12
30
45
85
122
234
345
345

What this does…

Gets a string from the standard input. Split the string into tokens delimited by whitespace. Convert each token to an int. Sort the output from the map() object and print

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading