Best way to merge/sort two sorted lists?...
Paul Rubin
http
Thu Jan 10 21:22:35 EST 2008
Aaron Watters <aaron.watters at gmail.com> writes:
> The second one is! That's why it works so fast.
> Tim Peters optimized this case!
> Gotta hand it to Tim Peters. The first one should
> win some sort of obfuscated code contest, imho.
> It also seems to be 5 times slower than any of the others.
The heapq method is the right way to do it when you want to
merge n lists instead of two lists. Each selection takes O(log n)
operations.
More information about the Python-list
mailing list