Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:code': 0.07; 'test,': 0.07; 'parameter': 0.09; 'try:': 0.09; 'valueerror:': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'def': 0.12; 'col': 0.16; 'subject: \n ': 0.16; 'subject:search': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'direction': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'url:python': 0.33; 'fri,': 0.33; 'subject:the': 0.34; 'except': 0.35; 'test': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'skip:j 20': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'nov': 0.38; 'url:mail': 0.40; 'break': 0.61; 'to:addr:gmail.com': 0.65; 'subject:this': 0.83; 'joel': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=5vvXzyXgR6I2ixlufu9TpBvQGsKYlV/XRv7RKo1PjwI=; b=Mw9zo7+nxgkihAcEuaS7RLBwZbzphm2ZDvBCAb+pU9ZQKhVqdmNMSEIAG9wBfnmVKP n1IOzDlrYQLBoelkn1uIR1wGCeoRdUVa4UHR4JVWaD4oZRNYZM4WjCR1n5GaRHAJKiS5 yW1+MYbC3iS975aMd/GcJ8aXKY7HQKhZR1NBlyG32CR+IWwfTTqULLKlG7+W9MF5ceAj iSB1zlvyI44OweSF4evzkUllMaBEQWpn5upN6p3OnhMbXMUpXXUjRIcbqTNjqh8Z5mvC 7sAz0EfYvuij0rpDB9tvIyj9AdAusvyfAtMcFWhzy6NzWlHlEysjnFge1qY+Him3lfj/ smCw== MIME-Version: 1.0 X-Received: by 10.229.79.132 with SMTP id p4mr21464049qck.14.1415395117741; Fri, 07 Nov 2014 13:18:37 -0800 (PST) In-Reply-To: References: Date: Fri, 7 Nov 2014 16:18:37 -0500 Subject: Re: How do i reduce this to a single function - the code is largely similar, just a direction of search toggle. From: Joel Goldstick To: Veek M Content-Type: text/plain; charset=UTF-8 Cc: "python-list@python.org" 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415395125 news.xs4all.nl 2843 [2001:888:2000:d::a6]:46113 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80384 On Fri, Nov 7, 2014 at 5:16 AM, Veek M wrote: > def jump_to_blockD(self): > end = len(self.b) > row, col = self.w.cursor > while row <= end: > try: > new_col = self.b[row].index('def') > self.w.cursor = row, new_col > break > except ValueError: > pass > row += 1 > > def jump_to_blockU(self): > end = 0 > row, col = self.w.cursor > while row >= end: > try: > new_col = self.b[row].rindex('def') > self.w.cursor = row, new_col > break > except ValueError: > pass > row -= 1 > > > > -- > https://mail.python.org/mailman/listinfo/python-list add a direction parameter to the call, and test direction to change the while test, and row increment/decrement -- Joel Goldstick http://joelgoldstick.com