Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89596
| 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 | 2015-04-29 21:08 -0600 |
| Subject | Re: Lucky numbers in Python |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.111.1430363360.3680.python-list@python.org> (permalink) |
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