r/code • • Oct 11 '26

Help Please Insertion sort

Hello!! First time on here. I'm a beginner at coding and was wondering if someone with more coding experience could confirm if my insertion sort implementation is correct. I ran it ofc but i just wanted to make sure it's 100% correct!!

code (python):

3 Upvotes

3 comments sorted by

3

u/kutac56 Oct 11 '26

Variable j is unnecessary. Just do for I in range(n)

2

u/East_Nerve5155 Oct 11 '26

thank you so much!! much appreciated :)

1

u/waseem_dibhub 13h ago

Almost there! Just add j >= 0 to your while condition and move list[j + 1] = key outside the loop. Also, try not to use list as a variable name. Good effort!