(Jan-16-2021, 12:35 PM)Serafim Wrote: 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.Oooh! I see! It makes sense. Not only removing one unnecessary step, but making the code efficient, and I'm all about efficiency. I'm learning, and this learning curve is HUGE right now; I'll be glad when it shrinks to the size of a needle point. Just started learning Python in November 2020, and even though I attained an associate’s degree in computer programming in 2016, I had no clue then how code worked, it was just over my head, so it's like all new to me. And I was able to attain my degree because so many people helped me get through the courses. Sadly, I didn't learn anything in computer programming, except how variables worked; I just got through the programming courses. That's sad. So as you can see by me asking you about the "1" in (1, len(lst)), I had no clue how the code was actually working to sort the list, but with that simple explanation of why "1" is in there, now I see how it works; I see the WHOLE code; I see how all the dots connect. YAAAHOOO!!! Thanks again!
Combine Two Recursive Functions To Create One Recursive Selection Sort Function
Users browsing this thread: 2 Guest(s)