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
#8
First would make a list of the numbers.
#Get user input
numb_list = []
numbers = input("Enter three numbers separated by space: ")
numb_list = [int(i) for i in numbers.split()]
sort_list = []
So could take the the first number in numb_list and compare if number is less(<) than other number in number list.
Then make a temporary variable,and append that number to sort_list and remove from numb_list.
All this is done as long as there are numbers in numb_list.
It's hard to explain this stuff Cry  

The start look like this:
while numb_list:
    first_number = numb_list[0]
    for n in numb_list:
        if n < first_number:
Do small test to understand it:
>>> lst = [50, 2, 1]
>>> for n in lst:
...     if n < 50:
...         print(n)
...         x = n
... 
2
1
>>> x
1

# x will always be the lowest number
>>> lst = [5, 100, 789, 4, 5678, 1, 444]
>>> for n in lst:
...     if n < 5:
...         print(n)
...         x = n
... 
4
1
>>> x
1
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

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