Implement the Selection Sort Algorithm - Implement the Selection Sort Algorithm

Tell us what’s happening:

it’s wroking and i think i made quite the same algorithme as the others posts , i really dont understand where is the problem here

Your code so far

def selection_sort(l):
    lenth=len(l)
    
    for i in range(lenth):
        for j in range(lenth):
            if l[i] <l[j]:
                l[j],l[i] =l[i],l[j]

    return l

tab=[12,3,45,5,8,78,2,8,4,7,-3,-72,-4]
print(selection_sort(tab))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36 OPR/133.0.0.0

Challenge Information:

Implement the Selection Sort Algorithm - Implement the Selection Sort Algorithm

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-selection-sort/680b3ef395479b0e449ecb6e.md at main · freeCodeCamp/freeCodeCamp · GitHub

Welcome to the forum @shokacine,

Testing with this function call:

print(selection_sort(\[1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92\]))

should swap only 10 times. But your code swaps 52 times.

Happy coding

thanks for the advice got it !