Skip to content

Instantly share code, notes, and snippets.

@felipernb
Created September 11, 2012 14:20
Show Gist options
  • Select an option

  • Save felipernb/3698965 to your computer and use it in GitHub Desktop.

Select an option

Save felipernb/3698965 to your computer and use it in GitHub Desktop.
Insertion Sort in Python
def insertion_sort(a):
for i in xrange(1, len(a)):
n = a[i]
pos = i
while pos > 0 and a[pos-1] > n:
a[pos] = a[pos-1]
pos -= 1
a[pos] = n
return a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment