Merging sorted lists/iterators/generators into one stream of values...

George Sakkis gsakkis at rutgers.edu
Sat Oct 8 14:50:47 EDT 2005


"Lasse Vågsæther Karlsen" <lasse at vkarlsen.no> wrote:

> George Sakkis wrote:
> <snip>
> > Just added a recipe at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440673. You can
try
> > both and see if there's any significant performance difference for your data.
> <snip>
>
> Thanks, will take a look at it later. The sort solution seems to work
> nicely. Might be a big difference if I have a lot of sources though as I
> bet the overhead in doing a sort of N items gets higher than doing a
> manipulation of a heap to place an item in the right spot, but with 4-5
> or a few more sources might not make an impact at all.

Unless you're talking about hundreds or thousands sources, it probably
won't. I would still go for the heap solution since IMO the resulting
code it's more readable and easier to understand.

George




More information about the Python-list mailing list