Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.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.092 X-Spam-Evidence: '*H*': 0.82; '*S*': 0.00; 'subject:Python': 0.06; 'bug': 0.12; 'doing,': 0.16; 'iteration': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'wondering': 0.29; 'message-id:@mail.gmail.com': 0.30; 'subject:numbers': 0.31; 'probably': 0.32; 'supposed': 0.32; 'received:google.com': 0.35; 'there': 0.35; 'list': 0.37; 'clear': 0.37; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'pm,': 0.38; 'delete': 0.39; 'to:addr:python.org': 0.39; 'deleting': 0.60; 'middle': 0.60; 'term': 0.63; 'more': 0.64; '2015': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=4Od+SkrPzALd5hBzTI2xdIOqOVv9r4KyEY7wqDT2N24=; b=OCKcSVE3tBDO03o7Jdz1chsovp8nm7y1Gn8EZcm1M4oKVx4cSo3k7XFv9Yx2jGw1VS WgJPqmChCPParyo7B2BHc9QRMEIdUs9iDoDn5Yq9p9yGw5gqKWhdMJ2OO5kg5dYonjNy 2RhMHpQEQEkA7zYr3rAgtwaYcxmp5g1EpRt69/mFaNbTSCfdEcgcUJTNU/PXiTNywQEF Ecdijcf5E7t+83Gf5Z7xCcNxvCvgvmKkBKFil5HINs/0B5QCbLXRrQ2ThifZmUd5VPl+ ziZQ0Zkcj8OV50KCPzfVh82JrDeyGIA4TfViOs/Pv6CPeO3ABuAiTw+gmS6sAh/nEtRS FeDQ== X-Received: by 10.42.226.8 with SMTP id iu8mr5399735icb.17.1430337504440; Wed, 29 Apr 2015 12:58:24 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <87lhhabxod.fsf@Equus.decebal.nl> References: <87lhhabxod.fsf@Equus.decebal.nl> From: Ian Kelly Date: Wed, 29 Apr 2015 13:57:44 -0600 Subject: Re: Lucky numbers in Python To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430337506 news.xs4all.nl 2845 [2001:888:2000:d::a6]:33197 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89572 On Wed, Apr 29, 2015 at 12:24 PM, Cecil Westerhof wrote: > I was wondering if there is a way to do this: > for del_index in range((sieve_len // skip_count) * skip_count - 1, > skip_count - 2, -skip_count): > del sieve[del_index] > in a more efficient way. You can delete using slices. del sieve[(sieve_len // skip_count) * skip_count - 1 : skip_count - 2 : -skip_count] Now you no longer need to do the iteration in reverse, which makes the slicing simpler: del sieve[skip_count - 1 : (sieve_len // skip_count) * skip_count : skip_count] And although it's not clear to me what this is supposed to be doing, you probably no longer need the middle term if the intention is to continue deleting all the way to the end of the list (if it is then I think you have a bug in the existing implementation, since the last item in the list can never be deleted). del sieve[skip_count - 1 :: skip_count]