RosettaCodeData/Task/Factors-of-an-integer/Python/factors-of-an-integer-2.py
2023-07-01 13:44:08 -04:00

5 lines
120 B
Python

>>> def factors(n):
return [i for i in range(1, n//2 + 1) if not n%i] + [n]
>>> factors(45)
[1, 3, 5, 9, 15, 45]