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

George Sakkis gsakkis at rutgers.edu
Sat Oct 8 20:14:39 CEST 2005


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

> Alex Martelli wrote:
> > George Sakkis <gsakkis at rutgers.edu> wrote:
> <snip>
> >>Yes, it's a little inconvenient that the builtin heap doesn't take a
> >>comparison operation but you can easily roll your own heap by transforming
> >>each item to a (key,item) tuple. Now that I'm thinking about it, it might
> >>be a good addition to the cookbook.
> >
> >
> > I believe Python 2.5 adds a key= argument to heapq's functions...
> <snip>
>
> I will revisit the heapq solution when 2.5 is released then.
>
> Thanks for the heads up. For the moment I will stay with the list
> solution that Mike came up with slightly changed to accomodate tips and
> pointers from others in this thread.

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.

George





More information about the Python-list mailing list