title: How does Python insertion sort work?
body: <p>Here's a Python implementation of insertion sort, I tried to follow the values on paper but once the counting variable i gets bigger than len(s) I don't know what to do, how/why does it still run?</p>
  
  <pre><code>def sort_numbers(s):
      for i in range(1, len(s)):
          val = s[i]
          j = i - 1
          while (j &gt;= 0) and (s[j] &gt; val):
              s[j+1] = s[j]
              j = j - 1
          s[j+1] = val
  
  def main():
      x = eval(input("Enter numbers to be sorted: "))
      x = list(x)
      sort_numbers(x)
      print(x)
  </code></pre>