What about an EXPLICIT naming scheme for built-ins?
Alex Martelli
aleaxit at yahoo.com
Thu Sep 9 03:45:49 EDT 2004
Raymond Hettinger <python at rcn.com> wrote:
...
> def itersort(arr):
> heapify(a)
> try:
> while a:
> yield heappop(a)
> except IndexError:
> pass
I think you're missing in this function a first line of
a = list(arr)
But otherwise, yep, this sure looks right, except that I'm not sure
about the need for the try/except (can't hurt, but if not needed it
might be better to make life simpler by removing it). Wouldn't...:
def isorted(seq):
a = list(seq)
heapify(a)
while a: yield heappop(a)
work just as well? What else but an empty a could trigger IndexError?
And if it's empty we're out of the ''while', so...
Alex
More information about the Python-list
mailing list