Skip to content

Instantly share code, notes, and snippets.

@canburak
Created September 28, 2013 18:16
Show Gist options
  • Save canburak/6744823 to your computer and use it in GitHub Desktop.
Save canburak/6744823 to your computer and use it in GitHub Desktop.
def merge_lists(l1, l2):
# If any of the lists are epty, return the other list
if not l1: return l2
if not l2: return l1
if l1[0] <= l2[0]:
# Prepend the smaller item to the merged version of the rest
return [l1[0]] + merge_lists(l1[1:], l2)
else:
return merge_lists(l2, l1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment