You were probably being rhetorical, but there are two problems:
- `p = 2` should be outside the loop
- `prime_factors.append(n)` appends `1` onto the end of the list for no reason
With those two changes I'm pretty sure it's correct.
def factorize(n): ... return prime_factors