14.8 LAB: Selection sort Write a program that takes an integer list as input and sorts the list into descending order using selection sort. The program should use nested loops and output the list after each iteration of the outer loop, thus outputting the list N-1 times (where N is the size of the list). Code I have so far: def selection_sort_descend_trace(lst): for i in range(len(lst) - 1): max_ind = i for j in range(i + 1, len(lst)): if lst[j] > lst[max_ind]: max_ind = j lst[i], lst[max_ind] = lst[max_ind], lst[i] print(' '.join([str(x) for x in lst])) return lst if __name__ == '__main__': numbers = [int(x) for x in input().split()] selection_sort_descend_trace(numbers) Error I am getting: How do i get the brackets and comma? Input 20 10 30 40 Your output 40 10 30 20 40 30 10 20 40 30 20 10 Expected output [40, 10, 30, 20] [40, 30, 10, 20] [40, 30, 20, 10]
14.8 LAB: Selection sort
Write a
Code I have so far:
def selection_sort_descend_trace(lst):
for i in range(len(lst) - 1):
max_ind = i
for j in range(i + 1, len(lst)):
if lst[j] > lst[max_ind]:
max_ind = j
lst[i], lst[max_ind] = lst[max_ind], lst[i]
print(' '.join([str(x) for x in lst]))
return lst
if __name__ == '__main__':
numbers = [int(x) for x in input().split()]
selection_sort_descend_trace(numbers)
Error I am getting:
How do i get the brackets and comma?
Step by step
Solved in 4 steps with 2 images