Created
March 8, 2022 02:52
-
-
Save tusharhero/5f85d77461283bd6eb07d07f1b1899ba to your computer and use it in GitHub Desktop.
this script will sort any number list from smallest to largest. Uses 2 functions. Only for ascending order. and only integers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
WRITTEN by Tushar Maharana | |
LICENSE: https://tusharhero.mit-license.org/ | |
this script will sort any number list from smallest to largest | |
''' | |
def sortedone(list):#function to sort a list. | |
l = 0#counter | |
ll = 0# counter | |
while l < len(list)-1: #while l is smaller than length - 1 | |
ll = l + 1 # because we want consecutive terms | |
a = list[l]# | |
b = list[ll]#coz we need to change the values | |
if a > b: | |
list[l] = b#then replace the values | |
list[ll] = a | |
l = l + 1# counter stuff | |
else: | |
l = l + 1# counter stuff | |
return list | |
def sorted(list):#this function will sortedone() to repeatedly make sure that list is sorted | |
k = 0#counter | |
while k < len(list):#while the length is not completed | |
listt = sortedone(list)#storing in listt | |
k = k + 1#counting | |
return listt#returning list | |
#driver | |
list = [0,2,24,9,6,1000,-1,9,0,1] | |
print(sorted(list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment