range() vs xrange() Python2|3 issues for performance

Chris Angelico rosuav at gmail.com
Thu Aug 4 08:59:07 CEST 2011


On Thu, Aug 4, 2011 at 4:01 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
>        a, b = divmod(n, i)
>        if b == 0:
>            total += a+i
>

Wouldn't this fail on squares? It happens to give correct results as
far as I've checked; no square up to 10,000 is called perfect, and
there are no perfect squares in that range, but I think it's
technically using an incorrect intermediate result.

ChrisA



More information about the Python-list mailing list