Skip to content

Instantly share code, notes, and snippets.

@ksdme
Created September 4, 2017 07:31
Show Gist options
  • Save ksdme/7f9a5385bb0c2aeff3f8787dc558e911 to your computer and use it in GitHub Desktop.
Save ksdme/7f9a5385bb0c2aeff3f8787dc558e911 to your computer and use it in GitHub Desktop.
A compact one line implementation of merge sort!
def merge_em(slice):
return slice if len(slice) == 1 else (lambda first, secon, buffed: (buffed + secon) if map(lambda _: ([buffed.append(secon.pop(_[0])) if two < _[1] else None for two in secon], buffed.append(_[1])), enumerate(first)) or True else None)(*(map(merge_em, (slice[:int(len(slice)/2)], slice[int(len(slice)/2):])) + [[]]))
print merge_em(map(int, raw_input("Enter Subjects: ").strip().split())), raw_input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment