Python Forum
Manual Sort without Sort function
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Manual Sort without Sort function
#27
Another way to do this is -
import time
#get valid input
while True:
    numList = []
    numbers = input('Type your numbers seperated by spaces: ')
    try:
        for num in numbers.split():
            #debug numbers starting with 0
            outputNum = ''
            zero = True
            for character in num:
                if character == '0' and zero:
                    pass
                else:
                    outputNum += character
                    zero = False
                        
            int(outputNum)
            numList.append(outputNum)
        break
    except:
        print('Invalid input detected. Please refer to the message below')

#Exit if they typed nothing
if not numList:
    print('If you didn\'t want to use me you could\'ve just clicked the red x')
    time.sleep(5)
    quit()

#Sort from least to most
outputList = []
for x in range(0, len(numList)):
    num = min(numList)
    outputList.append(num)
    numList.remove(num)

#print results
for output in outputList:
    print(output)

But for this assignment, only the debugging part from my code might be useful
Reply


Messages In This Thread
Manual Sort without Sort function - by dtweaponx - Oct-13-2017, 02:04 AM
RE: Manual Sort without Sort function - by buran - Oct-13-2017, 08:29 AM
RE: Manual Sort without Sort function - by snippsat - Oct-13-2017, 02:58 PM
RE: Manual Sort without Sort function - by wavic - Oct-13-2017, 06:33 PM
RE: Manual Sort without Sort function - by Mekire - Oct-13-2017, 11:28 PM
RE: Manual Sort without Sort function - by wavic - Oct-14-2017, 01:05 AM
RE: Manual Sort without Sort function - by Mekire - Oct-14-2017, 01:17 AM
RE: Manual Sort without Sort function - by SheeppOSU - Jun-01-2019, 06:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Frog codility leap sort variant MoreMoney 5 479 Apr-06-2024, 08:47 PM
Last Post: deanhystad
  How to sort a list with duplicates and return their unique indices. Echoroom 3 3,531 Sep-23-2022, 07:53 AM
Last Post: deanhystad
  sorting a list using unicodes acending order, no loops, no sort(), using recursion lrn2codee 14 6,463 Jun-23-2021, 07:33 PM
Last Post: deanhystad
  Sort and merge flintstone 1 1,934 Jun-14-2021, 07:32 PM
Last Post: Larz60+
  How can I sort my column so that NaN is at the bottom? soft 3 2,426 Feb-06-2021, 01:02 PM
Last Post: ibreeden
  how to sort a list without .sort() function letmecode 3 3,470 Dec-28-2020, 11:21 PM
Last Post: perfringo
  Sort on basis of (name,age,score) pyzyx3qwerty 9 9,607 May-14-2020, 08:29 AM
Last Post: pyzyx3qwerty
  Sort last pyzyx3qwerty 7 4,799 May-05-2020, 02:58 PM
Last Post: DeaD_EyE
  insertion sort brobro 3 2,231 Apr-24-2020, 01:29 PM
Last Post: Godserena
  Sort objects by protected properties. Sigriddenfeta 1 1,903 Mar-17-2020, 04:11 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020