Skip to content

Instantly share code, notes, and snippets.

@joshbarrass
Created June 10, 2018 21:11
Show Gist options
  • Save joshbarrass/813709a6ef0c4b7fb220a3e02c46214d to your computer and use it in GitHub Desktop.
Save joshbarrass/813709a6ef0c4b7fb220a3e02c46214d to your computer and use it in GitHub Desktop.
One-line merge sort in Python
olmerge = lambda l:l if len(l)==1 else (lambda l1,l2: ( lambda half,l1,l2: half+l1 if not len(l2) else half+l2 if not len(l1) else half+l1+l2 )([[l1.pop,l2.pop][l1[0]>l2[0]](0) for x in range([len(l1),len(l2)][len(l1)>len(l2)]*2) if (len(l1)>0 and len(l2)>0)],l1,l2) )(olmerge(l[:len(l)//2]),olmerge(l[len(l)//2:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment