def proper_divisors(n): """ Return the sum of the proper divisors of positive integer n """ return sum([x for x in range(1,n) if int(n/x) == n/x])
The list comprehension is this function is inefficient in that it computes n/x twice. I'd like to do an a = n/x and use a in "if int(a) == a", but I don't know how. Thanks, Dick Moores
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor