Re: Strange behaviour with reversed()

2007-10-19 Thread Andreas Kraemer
On Oct 19, 1:49 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > Andreas Kraemer <[EMAIL PROTECTED]> wrote: > >> The only other behaviours I would regard as intuitive for iteration over > >> a mutating sequence would be to throw an exception either for mutating > >> the sequence while the iterator exi

Re: Strange behaviour with reversed()

2007-10-19 Thread Duncan Booth
Andreas Kraemer <[EMAIL PROTECTED]> wrote: >> The only other behaviours I would regard as intuitive for iteration over >> a mutating sequence would be to throw an exception either for mutating >> the sequence while the iterator exists or for using the iterator after a >> mutation. > > Maybe it wo

Re: Strange behaviour with reversed()

2007-10-18 Thread Dustan
On Oct 18, 3:52 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Thu, 18 Oct 2007 15:24:27 +1000, Ben Finney wrote: > > Steven D'Aprano <[EMAIL PROTECTED]> writes: > > >> and help(reversed) but neither gives any insight to what happens when > >> you use reversed() on a sequenc

Re: Strange behaviour with reversed()

2007-10-18 Thread Terry Reedy
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] |I don't understand how reversed() is operating. I've read the description | in the docs: | | reversed(seq) | Return a reverse iterator. seq must be an object which supports the | sequence protocol (the __len__() method

Re: Strange behaviour with reversed()

2007-10-18 Thread Andreas Kraemer
On Oct 18, 2:25 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >> Note that the starting index is determined at creation time, not when > >> the iteration begins. So, if you create a reversed object over a list > >> containing 3 elements, the first return

Re: Strange behaviour with reversed()

2007-10-18 Thread Duncan Booth
Steven D'Aprano <[EMAIL PROTECTED]> wrote: >> Note that the starting index is determined at creation time, not when >> the iteration begins. So, if you create a reversed object over a list >> containing 3 elements, the first returned element will be seq[2], then >> seq[1], then seq[0]. It doesn't

Re: Strange behaviour with reversed()

2007-10-18 Thread Steven D'Aprano
On Thu, 18 Oct 2007 15:24:27 +1000, Ben Finney wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: > >> and help(reversed) but neither gives any insight to what happens when >> you use reversed() on a sequence, then modify the sequence. > > I would think the answer is the same for any question

Re: Strange behaviour with reversed()

2007-10-18 Thread Steven D'Aprano
On Thu, 18 Oct 2007 02:49:12 -0300, Gabriel Genellina wrote: > A reversed object is rather simple: it stores the original sequence (a > reference, as usual, not a copy!) and the next index to use, starting at > len-1. Each time the next() method is called, the index is decremented > until it goes

Re: Strange behaviour with reversed()

2007-10-17 Thread Andreas Kraemer
On Oct 17, 9:31 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > I don't understand how reversed() is operating. I've read the description > in the docs: > > reversed(seq) > Return a reverse iterator. seq must be an object which supports the > sequence protocol (the __len__() met

Re: Strange behaviour with reversed()

2007-10-17 Thread Gabriel Genellina
En Thu, 18 Oct 2007 01:31:13 -0300, Steven D'Aprano <[EMAIL PROTECTED]> escribió: > I don't understand how reversed() is operating. I've read the description > in the docs: > > reversed(seq) > Return a reverse iterator. seq must be an object which supports the > sequence protocol (the __len__()

Re: Strange behaviour with reversed()

2007-10-17 Thread Ben Finney
Steven D'Aprano <[EMAIL PROTECTED]> writes: > and help(reversed) but neither gives any insight to what happens > when you use reversed() on a sequence, then modify the sequence. I would think the answer is the same for any question about modifying sequences while iterating: "undefined, therefore

Strange behaviour with reversed()

2007-10-17 Thread Steven D'Aprano
I don't understand how reversed() is operating. I've read the description in the docs: reversed(seq) Return a reverse iterator. seq must be an object which supports the sequence protocol (the __len__() method and the __getitem__() method with integer arguments starting at 0). New in version 2.4