for iteration in range(len(list) - 1):
index = iteration +1 #This is the line which has no effect on the inner loop
for index in range(len(list)):
if list[iteration] > list[index]:
newmin = list[index]
newminindex = index
if iteration != newminindex :
swapnumbers(list,iteration, newminindex)
The above is a code snippet I wrote for selection sort algorithm. However I see the inner loop start counter always starting from 0. Request for expert comment.
range(15)(for example), it really saysrange(0,15). Using only one argument simplifies it for you (the programmer), but it is really saying the latter. You should simplify it tofor index in range(iteration + 1, len(myList)):. Also, try not to reuse variable names like you did here. When you sayfor index in...you reset the value of index you gave it the line before. As I assume you thought, setting index before does not affect its starting vale in theforloop. The value of index gets changed to the default value ofrange(oneArg):0, and with 2 args, the first value.