Re: What about an EXPLICIT naming scheme for built-ins?

From: Jason Lai (jmlai_at_uci.edu)
Date: 09/03/04


Date: Fri, 03 Sep 2004 08:27:11 -0700

Carlos Ribeiro wrote:
> On Sat, 4 Sep 2004 00:15:41 +1000, Andrew Durdin <adurdin@gmail.com> wrote:
>
>>However, I think it'd be hard to make an iterator implementation of
>>sorted() without either copying the sequence or resorting to O(n^2)
>>performance, which is not good.
>>This may just be an example where inconsistency is a practical necessity.
>
>
> You may be right. At the least, this reasoning could possibly be
> included in the FAQ, as it will probably turn out to be a frequent
> question in the near future. But having sorted() to return a iterator
> still sounds like a logical thing to do, so I'm not sure about it.
>

I had an idea for a moment about having sorted/reversed return the same
type as it was passed -- so reversed(seq) returns a seq,
reversed(iterator) returns an iterator. But it sounds confusing/magical
and maybe out of line with Python philosophy. Although I think the whole
iterator usage seems a little messy right now, so it's worth thinking
about how seq/iterators-related functions should behave.

  - Jason Lai



Relevant Pages

  • Re: docs on for-loop with no __iter__?
    ... "Andrew Dalke" wrote in message ... >] the sequence, in the order of ascending indices. ... "for" uses an adaptive method to try to simulate an iterator ... telling the pseudo-iterator that there are no more entries). ...
    (comp.lang.python)
  • Re: General question about Python design goals
    ... > calling it will of course fail as well. ... object via iter is sufficient to claim that you can iterate over it, ... never mind that actually using the iterator fails? ... > that's how python's sequence protocol works. ...
    (comp.lang.python)
  • Re: General question about Python design goals
    ... Therefore, once a tuple is e.g. turned into an iterator object, ... Someone is saying "I want to treat this as a sequence" when they write, e.g., iter. ... to the iter constructor. ... the iter call signature to accept multiple iterables, so e.g., iter.zip ...
    (comp.lang.python)
  • Re: Sequence iterators with __index__
    ... And slicing is all about offsets. ... could be reasonably used as indexes into a sequence. ... If the iterator uses in incrementing index to iterate, ...
    (comp.lang.python)
  • Re: iterable terminology (for language lawyers)
    ... And since strings are ... Examples of iterables include all sequence types (such as list, str, ... This iterator is good for one pass over the ...
    (comp.lang.python)