Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58254

Re: "Backward"-Iterator - Beginners question

Date 2013-11-01 11:18 +0100
From Ulrich Goebel <ml@fam-goebel.de>
Subject Re: "Backward"-Iterator - Beginners question
References <5272CBA8.3070800@fam-goebel.de> <l4uluh$l7s$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.1917.1383301090.18130.python-list@python.org> (permalink)

Show all headers | View raw


Hi

Am 31.10.2013 23:35, schrieb Terry Reedy:
> On 10/31/2013 5:29 PM, Ulrich Goebel wrote:
>
>> I'm locking for an "iterator" type with not only the .next() method, but
>> with a .previous(), .first() and .last() method, so that I can through
>> it from the beginning or from the end, and in both directions, even
>> alternately (for example two steps forward, one backward, two steps
>> forward).
>
> You are free to write such a class, if it is appropriate for your actual
> use case.

Ok, possibly I will try that later...

> If you have a concrete sequence object seq with random access, there is
> no reason to do so. First and last are seq[0] and seq[-1]. Given
> 'cursor' i, prev and next are 'i-=1;seq[i]' and 'i+=1;seq[i]'.

That gives me the solution. What I have, is an iterator object comming 
as a SQLite database cursor object. So I could minimize the underliying 
SELECT and build index = list(cursor). Then with Your hints I get what I 
want.

Thanks
Ulrich

-- 
Ulrich Goebel
Paracelsusstr. 120, 53177 Bonn

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: "Backward"-Iterator - Beginners question Ulrich Goebel <ml@fam-goebel.de> - 2013-11-01 11:18 +0100

csiph-web