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]

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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]
Expected output
3: Compare output
Your output
88 79 52 45 33
Output differs. See highlights below.
Input
Expected output
[88, 79, 52, 33, 45]
[88, 79, 52, 33, 45]
[88, 79, 52, 33, 45]
[88, 79, 52, 45,
33]
1 2 3 4 5 6 7 8 9
9 2 3 4
9 8 3
9 8 7 4
9 8 7
9 8 7
9 8 7
9 8 7
4
9 8 7
6
6
6
6
5 6
5 6
5
5
5
5
5
6 5
6
4
4
4
4
4
7
4
7
3
3
3
3
8
3
2
2
2
2
2
3 2
2
1
1
1
1
1
1
1
1
[9, 2, 3, 4, 5,
6, 7, 8,
1]
[9, 8, 3,
5,
6, 7, 2, 1]
I
[9, 8, 7, 4, 5, 6, 3, 2, 1]
4,
3, 2,
1]
6, 5,
6, 5,
4, 3, 2, 1]
[9, 8, 7,
[9, 8, 7,
[9, 8, 7,
[9, 8, 7,
6, 5,
6,
HHHHH
4, 3, 2,
1]
5, 4, 3, 2, 1]
0/2
Transcribed Image Text:Expected output 3: Compare output Your output 88 79 52 45 33 Output differs. See highlights below. Input Expected output [88, 79, 52, 33, 45] [88, 79, 52, 33, 45] [88, 79, 52, 33, 45] [88, 79, 52, 45, 33] 1 2 3 4 5 6 7 8 9 9 2 3 4 9 8 3 9 8 7 4 9 8 7 9 8 7 9 8 7 9 8 7 4 9 8 7 6 6 6 6 5 6 5 6 5 5 5 5 5 6 5 6 4 4 4 4 4 7 4 7 3 3 3 3 8 3 2 2 2 2 2 3 2 2 1 1 1 1 1 1 1 1 [9, 2, 3, 4, 5, 6, 7, 8, 1] [9, 8, 3, 5, 6, 7, 2, 1] I [9, 8, 7, 4, 5, 6, 3, 2, 1] 4, 3, 2, 1] 6, 5, 6, 5, 4, 3, 2, 1] [9, 8, 7, [9, 8, 7, [9, 8, 7, [9, 8, 7, 6, 5, 6, HHHHH 4, 3, 2, 1] 5, 4, 3, 2, 1] 0/2
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY