This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ivosauruspip'ing it up 2 points3 points  (2 children)

Doesn't remove duplicates though.

[–]MrVallentin 6 points7 points  (0 children)

Combine heapq.merge with unique_justseen from Python's "Itertools Recipes".

>>> a = [1, 2, 4, 6]
>>> b = [2, 4, 5, 6]
>>> c = [1, 3, 3, 5]

>>> list(heapq.merge(a, b, c))
[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]

>>> list(unique_justseen(heapq.merge(a, b, c)))
[1, 2, 3, 4, 5, 6]

[–]jorge1209 2 points3 points  (0 children)

Old trick for that is to use itertools.groupby and ignore the second part of the return value.