What about an EXPLICIT naming scheme for built-ins?
ptmcg at austin.rr._bogus_.com
Fri Sep 3 22:26:13 CEST 2004
"David Fraser" <davidf at sjsoft.com> wrote in message
news:chai28$pd8$1 at ctb-nnrp2.saix.net...
> Marco Aschwanden wrote:
> > I just read the changes for 2.4 and while scanning the list the past
> > tense built-ins got my attention:
> > sorted() - a new builtin sorted() acts like an in-place list.sort() but
> > can be used in expressions, as it returns a copy of the sequence,
> > reversed() - a new builtin that takes a sequence and returns an iterator
> > that loops over the elements of the sequence in reverse order (PEP 322)
> > sort() works in-place.
> > reverse() works in-place.
> How about reversed() returning a sequence, like sorted does, but adding
> an iterator function called riter or reverseiter to iterate over
> sequences in reverse order. That would then be similar to the iter
> builtin. You could have a sortediter as well
Huh! I just assumed that sorted() and reversed() would both return new
lists, one sorted, and one reversed. I should think if you wanted an
iterator, you could use iter(sorted(x)) or iter(reversed(x)). But to get an
iterator over the reverse of a sequence, without making a copy of the
sequence, then this should have a different name, something like riter, or
In the current system, how does one construct a reversed list?
- revx = x[::-1]
- revx = [ i for i in reversed(x) ]
- revx = [tooth for tooth in ... ] # not a real example, just wanted to
follow up after "i for i"
(What if you wrote a sorted_iter that would iterate over an existing list in
More information about the Python-list