I have made a function that finds all divisors that runs decently fast but for what I am trying to do I want it to run faster. I have also already created a primeFactors function. What I am doing is finding all possible powers that can be made and multiplying them.
from functools import reduce
from itertools import product
def divisors(n):
x = sorted(primeFactors(n))
r = []
for values in set(x):
t = list(range(0, x.count(values) + 1))
r.append(t)
comb = list(product(*r))
divisors = []
for sets in comb:
n = [a**b for a, b in zip(set(x), sets)]
divisors.append(reduce(lambda x, y: x*y, n))
return sorted(divisors)
Is there another approach that is faster or any improvements that can be made to this code to make it faster? For the sake of the problem lets assume my primeFactors is the fastest in the world.