Re: Lucky numbers in Python

2015-04-30 Thread Dave Angel
On 04/30/2015 02:55 PM, Cecil Westerhof wrote: Because I want the code to work with Python 3 also, the code is now: def lucky_numbers(n): """ Lucky numbers from 1 up-to n http://en.wikipedia.org/wiki/Lucky_number """ if n < 3: return

Re: Lucky numbers in Python

2015-04-30 Thread Cecil Westerhof
Because I want the code to work with Python 3 also, the code is now: def lucky_numbers(n): """ Lucky numbers from 1 up-to n http://en.wikipedia.org/wiki/Lucky_number """ if n < 3: return [1] sieve = list(range(1, n + 1, 2)) si

Re: Lucky numbers in Python

2015-04-30 Thread Cecil Westerhof
Op Thursday 30 Apr 2015 04:55 CEST schreef Ian Kelly: > On Wed, Apr 29, 2015 at 6:01 PM, Cecil Westerhof wrote: >> Op Thursday 30 Apr 2015 00:38 CEST schreef Ian Kelly: >>> In that case you can definitely omit the middle term of the slice, >>> which will be both more concise and clearer in intent

Re: Lucky numbers in Python

2015-04-29 Thread Ian Kelly
On Wed, Apr 29, 2015 at 6:11 PM, Steven D'Aprano wrote: > On Thu, 30 Apr 2015 05:57 am, Ian Kelly wrote: > >> 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

Re: Lucky numbers in Python

2015-04-29 Thread Ian Kelly
On Wed, Apr 29, 2015 at 6:01 PM, Cecil Westerhof wrote: > Op Thursday 30 Apr 2015 00:38 CEST schreef Ian Kelly: >> In that case you can definitely omit the middle term of the slice, >> which will be both more concise and clearer in intent, though >> probably not significantly faster. > > It is cer

Re: Lucky numbers in Python

2015-04-29 Thread Cecil Westerhof
Op Thursday 30 Apr 2015 00:38 CEST schreef Ian Kelly: > On Wed, Apr 29, 2015 at 3:45 PM, Cecil Westerhof wrote: >> Op Wednesday 29 Apr 2015 21:57 CEST schreef Ian Kelly: >>> 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

Re: Lucky numbers in Python

2015-04-29 Thread Steven D'Aprano
On Thu, 30 Apr 2015 05:57 am, Ian Kelly wrote: > 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_c

Re: Lucky numbers in Python

2015-04-29 Thread Chris Kaynor
On Wed, Apr 29, 2015 at 2:45 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 usin

Re: Lucky numbers in Python

2015-04-29 Thread Ian Kelly
On Wed, Apr 29, 2015 at 3:45 PM, Cecil Westerhof wrote: > Op Wednesday 29 Apr 2015 21:57 CEST schreef Ian Kelly: >> 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

Re: Lucky numbers in Python

2015-04-29 Thread Cecil Westerhof
Op Wednesday 29 Apr 2015 21:57 CEST schreef Ian Kelly: > 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

Re: Lucky numbers in Python

2015-04-29 Thread Ian Kelly
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

Lucky numbers in Python

2015-04-29 Thread Cecil Westerhof
I wrote a function lucky_numbers: def lucky_numbers(n): if n < 3: return [1] sieve = range(1, n + 1, 2) sieve_index = 1 while True: skip_count = sieve[sieve_index] sieve_len = len(sieve) if sieve_len < skip_count