I'm kind of new to programming. I'm trying to write an algorithm in python that gives all the prime factors of a number:
factors=[]
def factor(n):
for i in range(2,n+1):
if n%i==0:
factors.append(i)
factor(int(n/i))
break
return factors
It works, but whenever I run the 'factor' function again, it just appends to the already populated 'factors' list - how can I get the list to clear each time the function 'factor' is run?