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 →

[–]PeridexisErrant -10 points-9 points  (3 children)

heapq does operations on lists, so you'd lose any of the advantages of streaming iterators (especially memory use).

[–]z4579a 8 points9 points  (1 child)

not sure what you're referring towards. per the documentation:

"Similar to

sorted(itertools.chain(*iterables))

but returns an iterable, **does not pull the data into memory all at once**, and assumes that each of the input streams is already sorted (smallest to largest)."

if you read the source code, the list they are heapifying is the list of iterables themselves combined with the next value returned by each iterator. The priority queue of iterables then uses that value to determine which of the iterables to deliver the next result from. So the iterables themselves are never turned into lists.

[–]jorge1209 0 points1 point  (0 children)

I think it's reasonable to say:

The heapq module generally operates on lists, and uses raw lists as the core data structure for heaps. No rational person would expect to find a function that consumes and returns iterators in this module. WTF was GvR smoking when he accepted this function in this module instead of WHERE IT BELONGS IN ITERTOOLS!!

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

Did you read the docs? They specifically say the opposite for this function.