"Steven D'Aprano" <st...@pearwood.info> wrote
I'm going to be pedantic here... but to quote the Middleman,
specificity is the soul of all good communication.
Be pedantic! :-)
I really liked the explanation although I already sort of knew most of
it.
But there were a few nuggets in there I'd missed, like range() being
a type all of its own.
But one, slightly off-topic, question:
def proper_divisors(n):
return sum(x for x in range(1, int(math.sqrt(n))) if n%x == 0)
Why use math.sqrt() instead of just using the ** operator?
return sum(x for x in range(1, int(n**0.5)) if n%x == 0)
I'd have expected ** to be significantly faster than calling the
function, and given this is a performance tweak...?
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor