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


Groups > comp.lang.python > #89572

Re: Lucky numbers in Python

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 <ian.g.kelly@gmail.com>
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 <ian.g.kelly@gmail.com>
Date Wed, 29 Apr 2015 13:57:44 -0600
Subject Re: Lucky numbers in Python
To Python <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.95.1430337506.3680.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Wed, Apr 29, 2015 at 12:24 PM, Cecil Westerhof <Cecil@decebal.nl> 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]

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


Thread

Lucky numbers in Python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 20:24 +0200
  Re: Lucky numbers in Python Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-29 13:57 -0600
    Re: Lucky numbers in Python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 23:45 +0200
      Re: Lucky numbers in Python Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-29 16:38 -0600
        Re: Lucky numbers in Python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 02:01 +0200
          Re: Lucky numbers in Python Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-29 20:55 -0600
            Re: Lucky numbers in Python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 08:34 +0200
      Re: Lucky numbers in Python Chris Kaynor <ckaynor@zindagigames.com> - 2015-04-29 15:56 -0700
    Re: Lucky numbers in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-30 10:11 +1000
      Re: Lucky numbers in Python Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-29 21:08 -0600
  Re: Lucky numbers in Python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 20:55 +0200
    Re: Lucky numbers in Python Dave Angel <davea@davea.name> - 2015-04-30 15:28 -0400

csiph-web