Created
November 29, 2017 08:30
-
-
Save karliss/b0da20aa642e4bdfeab5111715da5230 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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