title: Trying to understand insertion sort algorithm
body: <p>I'm reading some books on Python, data structures, and analysis and design of algorithms. I want to really understand the in's and out's of coding, and become an efficient programmer. It's difficult to ask the book to clarify, hence my question on stackoverflow. I'm really finding Algorithms and recursion challenging ... I posted some code (insertion sort) below that I'm trying to understand exactly what's happening. I understand, generally, what is supposed to happen, but I'm not really getting the how and why.</p>
  
  <p>From trying to analyze pieces of the code on Python Idle, I know that:</p>
  
  <pre><code>key (holds variables) = 8, 2, 4, 9, 3, 6
  </code></pre>
  
  <p>and that:</p>
  
  <pre><code>i (holds the length) = 7 ( 1, 2, 3, 4, 5, 6, 7)
  </code></pre>
  
  <p>I don't know why 1 is used in the first line: range(1, len(mylist)). Any help is appreciated.</p>
  
  <pre><code>mylist = [8, 2, 4, 9, 3, 6]
  
  for j in range(1,len(mylist)):
      key = mylist[j]
      i = j
      while i &gt; 0 and mylist[i-1] &gt; key:
          mylist[i] = mylist[i - 1]
          i -= 1
          mylist[i] = key
  </code></pre>