Answer to Question #184220 in Python for python

Question #184220

Write a functionthat takes unsorted list as a parameter and return a sorted listin decending order(Do notuse any built-in function)


1
Expert's answer
2021-04-23T09:19:33-0400
def sort_list(numbers):
    for i in range(len(numbers)):
        for j in range(len(numbers)-i-1):
            if numbers[j] < numbers[j+1]:
                temp = numbers[j]
                numbers[j] = numbers[j+1]
                numbers[j+1] = temp
                
    return numbers




numbers = [3,4,1,6,7,8,-2,0,5,4]
print("numbers: ", numbers)


sorted_numbers = sort_list(numbers)
print("sorted numbers: ", sorted_numbers)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS