Below is the code for knowing all the prime factors of a number. I think there must be some better way of doing the same thing. Also, please tell me if there are some flaws in my code.
def factorize(num):
res2 = "%s: "%num
res = []
while num != 1:
for each in range(2, num + 1):
quo, rem = divmod(num, each)
if not rem:
res.append(each)
break
num = quo
pfs = set(res)
for each in pfs:
power = res.count(each)
if power == 1:
res2 += str(each) + " "
else:
res2 += str(each) + '^' + str(power) + " "
return res2