Skip to content

Instantly share code, notes, and snippets.

@karliss
Created November 29, 2017 08:30
Show Gist options
  • Save karliss/b0da20aa642e4bdfeab5111715da5230 to your computer and use it in GitHub Desktop.
Save karliss/b0da20aa642e4bdfeab5111715da5230 to your computer and use it in GitHub Desktop.
from heapq import merge
def merge_lists(lists):
if not lists:
return []
while len(lists) > 1:
a=[]
new_lists = []
if len(lists) % 2:
new_lists.append(lists.pop())
for a, b in zip(lists[::2], lists[1::2]):
new_lists.append(merge(a, b))
lists = new_lists
return lists[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment