Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89596
| Path | csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'algorithm': 0.04; 'true,': 0.05; 'subject:Python': 0.06; 'indexing': 0.07; 'remaining': 0.07; 'correct,': 0.09; 'expense': 0.09; 'none)': 0.09; 'iteration': 0.16; 'placeholder': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'thu,': 0.19; '>>>': 0.22; 'example': 0.22; 'separate': 0.22; "aren't": 0.24; 'removed.': 0.24; 'this:': 0.26; '(for': 0.26; 'header:In- Reply-To:1': 0.27; 'wondering': 0.29; 'am,': 0.29; 'especially': 0.30; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'subject:numbers': 0.31; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'list': 0.37; 'depends': 0.38; 'lists.': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'skip:- 10': 0.38; 'pm,': 0.38; 'previous': 0.38; 'rather': 0.38; 'delete': 0.39; 'to:addr:python.org': 0.39; 'deleting': 0.60; 'ian': 0.60; 'most': 0.60; "you're": 0.61; 'more': 0.64; '2015': 0.84; '6:11': 0.84; 'items,': 0.91 |
| 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=/UvC99jLq3awKfe+XcB9rsuQGVZE1T2b5SvGXY/SAYk=; b=s7TT55BgLDO8gNprjVll3f72as8ze7KNOUuPEjiAGQeu/XXtDU8q1auBKGmgUDHwI5 DmYF4HVwrXZLPl+FUH1QHK+lNSTbglQNH/MqBLxnzGwROjKFUPwUZVjEMUM6qThrD/vq 7dZbKBdBHdqQxYGbKtFoqgjysbiufxy/lY9+HbzSHugHiRMDoR22xT69COO3Xi4Vsudr Vr4sYgxi1XgyBeJrjomwD7mUItfpG9q6mEJwNUT3qMGQomiF/xrYyG0Ztg++LRArQQn3 l/mDqlhH/Nl4lIJJQSLB8pYeRNKzkUv+GkQBDQna5neTXZzSoZlzQLY9Hzr5Aw4WinCd f3zg== |
| X-Received | by 10.107.12.158 with SMTP id 30mr2695748iom.61.1430363357363; Wed, 29 Apr 2015 20:09:17 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <5541734a$0$12995$c3e8da3$5496439d@news.astraweb.com> |
| References | <87lhhabxod.fsf@Equus.decebal.nl> <mailman.95.1430337506.3680.python-list@python.org> <5541734a$0$12995$c3e8da3$5496439d@news.astraweb.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Wed, 29 Apr 2015 21:08:36 -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.111.1430363360.3680.python-list@python.org> (permalink) |
| Lines | 35 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1430363360 news.xs4all.nl 2823 [2001:888:2000:d::a6]:33353 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:89596 |
Show key headers only | View raw
On Wed, Apr 29, 2015 at 6:11 PM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: > On Thu, 30 Apr 2015 05:57 am, Ian Kelly wrote: > >> 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] > > True, but *probably* at the expense of speed. When you delete items from a > list, the remaining items have to be moved, which takes time, especially > for very large lists. > > Most of the time, rather than deleting items, it is faster to set them to a > placeholder (for example None) and then copy the ones which aren't None in > a separate loop: You're correct, but I think this would be difficult to apply to the OP's algorithm since the list indexing depends on the items from previous iterations having been removed.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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