0
Ascending order without conditions
Sort the list in ascending order without using conditions
11 Réponses
0
list.sort()
It doesn't have conditions and list will be sorted.
0
With logically
0
Sorting manually
0
So you mean manually without using inbuilt functions?
0
https://code.sololearn.com/c94LoiaLgeOH/?ref=app
I hope this helps you.
With this code you can sort a list without using any inbuilt function.
0
Yes, that's right
0
Also I need program of registration form, to clear an interview so please help with code and explanation, it will be helpful
0
I need explanation for above ascending order code, if u don't mind..
0
a=[1,3,5,4,7,2,3]
def check(a):
for i in range(len(a)-1):
if a[i]>a[i+1]:
return False
while check(a) == False:
for i in range(len(a)-1):
if a[i]>a[i+1]:
a[i],a[i+1]=a[i+1],a[i]
print(a)
What this code does is that we have defined a function to check whether the list is sorted or not. How does this function check it? It's simple. In a sorted list the element that comes before is either smaller or equal. This function returns False if that is not the case with the list. Now combined with this function is a while loop, which checks the condition. The while loop will continue until the condition become true which if only possible when list is sorted, so it willl execute until the list is sorted. Here comes the main part... The for loop will check the two elements and compare them. If a larger number comes before the smaller one, those two are swapped. It is continued until the whole is list is sorted. And Finally the list is sorted! Hope you understood.
0
MD Thoùfèék Thoufi If you still didn't understand, I can explain it more briefly by messaging you if you want.
0
For more details-
https://www.sololearn.com/learn/774/?ref=app