Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'class,': 0.07; 'received:192.168.178': 0.07; 'cursor': 0.09; 'method,': 0.09; 'subject:question': 0.10; 'random': 0.14; '120,': 0.16; 'goebel': 0.16; 'iterator': 0.16; 'prev': 0.16; 'received:192.168.178.20': 0.16; 'sqlite': 0.16; 'index': 0.16; 'appropriate': 0.16; 'so.': 0.16; 'wrote:': 0.18; 'solution.': 0.20; 'select': 0.22; 'example': 0.22; 'header:User-Agent:1': 0.23; 'case.': 0.24; 'possibly': 0.26; '(for': 0.26; 'header:In-Reply-To:1': 0.27; 'have,': 0.30; "i'm": 0.30; 'gives': 0.31; "skip:' 10": 0.31; 'end,': 0.31; 'object.': 0.31; 'beginning': 0.33; 'actual': 0.34; 'could': 0.34; 'but': 0.35; 'there': 0.35; 'sequence': 0.36; 'next': 0.36; 'thanks': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'even': 0.60; 'access,': 0.60; 'free': 0.61; 'first': 0.61; 'received:217': 0.63; 'such': 0.63; 'hints': 0.68; 'directions,': 0.84; 'forward,': 0.84; 'later...': 0.84 Date: Fri, 01 Nov 2013 11:18:07 +0100 From: Ulrich Goebel User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: "Backward"-Iterator - Beginners question References: <5272CBA8.3070800@fam-goebel.de> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383301091 news.xs4all.nl 15864 [2001:888:2000:d::a6]:34877 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:58254 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