+ 1

Would anyone describe this code logic ?

I want to find out the logic of this code for sorting numbers, thanks for your help https://code.sololearn.com/cXdMpw73e2M7/?ref=app

30th Nov 2020, 7:31 PM
NIMA
NIMA - avatar
2 Respostas
+ 10
NIMA , this should be Bubble Sort. It is not the fastest way of sorting, but gives a good example how an algorithm could work. Here is a link to a file in sololearn, that can play animations on how it works: https://www.google.com/url?sa=t&source=web&rct=j&url=https://code.sololearn.com/WRK8Y6Bkj9eP/&ved=2ahUKEwji65bvhavtAhVJTBoKHcJWBk0QjjgwBnoECAcQAQ&usg=AOvVaw1HgbLFfoduEA4SNlhZYRRL Steven M , you are right, that it makes more sense to use an approved and stable way to sort data by a python method or built-in function. But it is good to know how sorting can be done, and if a coder is able to read and understand this kind of code. It is very common in assignment / job interviews that you will be asked to give a statement to various sorting implementations.
30th Nov 2020, 8:01 PM
Lothar
Lothar - avatar
+ 2
#Looks like a more complex way of sorting from least to greatest. #The sorted() function does the same thing. def main (): scores = [ 60 , 50 , 95 , 80 , 70 ] print(sorted(scores))
30th Nov 2020, 7:42 PM
Steven M
Steven M - avatar