Proper divisors: Difference between revisions

(1 has no proper divisors.)
Line 164:
 
=={{header|Python}}==
{{incorrect|Python|1 has no proper divisors.}}
===Python: Literal===
A very literal interpretation
<lang python>>>> def proper_divs2(n):
... return {x for x in range(1, (n + 1) // 2 + 1) if n % x == 0 and n != x}
...
>>> [proper_divs2(n) for n in range(1, 11)]
[{1}set(), {1}, {1}, {1, 2}, {1}, {1, 2, 3}, {1}, {1, 2, 4}, {1, 3}, {1, 2, 5}]
>>>
>>> n, length = max(((n, len(proper_divs2(n))) for n in range(1, 20001)), key=lambda pd: pd[1])
Line 233 ⟶ 232:
except KeyError:
pass
return divs or ({1} if n != 1 else set())
 
 
Line 243 ⟶ 242:
 
{{out}}
<pre>[{1}set(), {1}, {1}, {1, 2}, {1}, {1, 2, 3}, {1}, {1, 2, 4}, {1, 3}, {1, 2, 5}]
15120 79</pre>
Anonymous user