Skip to content

Instantly share code, notes, and snippets.

@multivac61
Last active January 9, 2017 23:24
Show Gist options
  • Save multivac61/844d95f5c8b4ef6e3938 to your computer and use it in GitHub Desktop.
Save multivac61/844d95f5c8b4ef6e3938 to your computer and use it in GitHub Desktop.
def insertion_sort(m, sort_by=(lambda a, b: a < b)):
def insert_item(m, item0):
for i, item in enumerate(m):
if sort_by(item0, item):
m.insert(i, item0)
return
m.append(item0)
if len(l) <= 1:
return l
sorted_list = []
for item in l:
insert_item(sorted_list, item)
return sorted_list
@AndreiGhiurea
Copy link

Should be 'm', instead of 'l' for lines 9 and 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment