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


Groups > comp.lang.python > #58254 > unrolled thread

Re: "Backward"-Iterator - Beginners question

Started byUlrich Goebel <ml@fam-goebel.de>
First post2013-11-01 11:18 +0100
Last post2013-11-01 11:18 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#58254 — Re: "Backward"-Iterator - Beginners question

FromUlrich Goebel <ml@fam-goebel.de>
Date2013-11-01 11:18 +0100
SubjectRe: "Backward"-Iterator - Beginners question
Message-ID<mailman.1917.1383301090.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web