Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!news2.arglkargh.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!newsfeed.pionier.net.pl!feed.xsnews.nl!border03.ams.xsnews.nl!feeder04.ams.xsnews.nl!feeder01.ams.xsnews.nl!abp002.ams.xsnews.nl!frontend-F09-10.ams.news.kpn.nl From: Cecil Westerhof Newsgroups: comp.lang.python Subject: Re: Lucky numbers in Python Organization: Decebal Computing References: <87lhhabxod.fsf@Equus.decebal.nl> <87d22mbod7.fsf@Equus.decebal.nl> X-Face: "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR,v+Pti8=Vi/Z"g^?b"E X-Homepage: http://www.decebal.nl/ Date: Thu, 30 Apr 2015 02:01:02 +0200 Message-ID: <871tj2bi2p.fsf@Equus.decebal.nl> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:gjBV3bYux2rhwehIGnnC+ilhJMA= MIME-Version: 1.0 Content-Type: text/plain Lines: 33 NNTP-Posting-Host: 81.207.62.244 X-Trace: 1430352889 news.kpn.nl 19877 81.207.62.244@kpn/81.207.62.244:46745 Xref: csiph.com comp.lang.python:89590 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 >>> 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). >> >> What do you mean by this? Executing: >> lucky_numbers(5) >> gives: >> [1, 3] >> >> So the last element (5) is deleted. > > Off by one error on my part. This is why negative skip values on > ranges and slices are not recommended: they're confusing. :-) > > 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. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof