Lucky numbers in Python

Ian Kelly ian.g.kelly at
Thu Apr 30 04:55:29 CEST 2015

On Wed, Apr 29, 2015 at 6:01 PM, Cecil Westerhof <Cecil at> 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 certainly nit faster. It is even significantly slower. With the
> middle term lucky_numbers(int(1e6)) takes 0.13 seconds. Without it
> takes 14.3 seconds. Hundred times as long.

That would be rather surprising, since it's the same operation being
performed, so I did my own timing and came up with 0.25 seconds (best
of 3) with the middle term and 0.22 seconds without.

I suspect that you tested it as "del sieve[skip_count - 1 :
skip_count]" (which would delete only one item) rather than "del
sieve[skip_count - 1 :: skip_count]".

More information about the Python-list mailing list