0

Ascending order without conditions

Sort the list in ascending order without using conditions

18th Feb 2020, 3:25 PM
MD Thoùfèék Thoufi
MD Thoùfèék Thoufi - avatar
11 Antworten
0
list.sort() It doesn't have conditions and list will be sorted.
18th Feb 2020, 3:28 PM
Utkarsh Sharma
Utkarsh Sharma - avatar
0
With logically
19th Feb 2020, 1:38 PM
MD Thoùfèék Thoufi
MD Thoùfèék Thoufi - avatar
0
Sorting manually
19th Feb 2020, 1:39 PM
MD Thoùfèék Thoufi
MD Thoùfèék Thoufi - avatar
0
So you mean manually without using inbuilt functions?
19th Feb 2020, 1:53 PM
Utkarsh Sharma
Utkarsh Sharma - avatar
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.
19th Feb 2020, 2:12 PM
Utkarsh Sharma
Utkarsh Sharma - avatar
0
Yes, that's right
19th Feb 2020, 2:12 PM
MD Thoùfèék Thoufi
MD Thoùfèék Thoufi - avatar
0
Also I need program of registration form, to clear an interview so please help with code and explanation, it will be helpful
19th Feb 2020, 2:13 PM
MD Thoùfèék Thoufi
MD Thoùfèék Thoufi - avatar
0
I need explanation for above ascending order code, if u don't mind..
19th Feb 2020, 2:16 PM
MD Thoùfèék Thoufi
MD Thoùfèék Thoufi - avatar
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.
19th Feb 2020, 2:19 PM
Utkarsh Sharma
Utkarsh Sharma - avatar
0
MD Thoùfèék Thoufi If you still didn't understand, I can explain it more briefly by messaging you if you want.
19th Feb 2020, 2:25 PM
Utkarsh Sharma
Utkarsh Sharma - avatar
19th Feb 2020, 6:06 PM
Utkarsh Sharma
Utkarsh Sharma - avatar