Jan-16-2021, 12:35 PM
(Jan-16-2021, 09:48 AM)Jeremy7 Wrote: Hi Serafim, in your "for loop" in this code, what is the purpose of the "1" in "(1, len(lst))," because as I was studying the code to see how everything worked together to sort the list, I couldn't figure out what the purpose of the "1" was, so I deleted it to see if the code would still work, and it still works?range(len(lst)) means [0, 1, 2, ..., len(lst)-1] and range(1, len(lst)) starts at 1, giving [1, 2, ..., len(lst)-1] and as I use lst[0] as start value (element = lst[0]) I would, in the first step compare lst[0] < lst[0] if the loop was over range(len(lst)), which I know is false so I just skip that first step. It works with both constructs but my way skips one unnecessary test. Old programming habit, minimize work if obvious.