Skip to content

Instantly share code, notes, and snippets.

@mahmoudhossam
Created February 8, 2013 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahmoudhossam/4740255 to your computer and use it in GitHub Desktop.
Save mahmoudhossam/4740255 to your computer and use it in GitHub Desktop.
Insertion sort in Python.
def insertion_sort(seq):
j = 1
for i in range(1, len(seq)):
j = i
while j > 0 and seq[j] < seq[j-1]:
seq[j], seq[j-1] = seq[j-1], seq[j]
j -= 1
return seq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment