Skip to content

Instantly share code, notes, and snippets.

@ssanin82
Created January 21, 2015 03:28
Show Gist options
  • Save ssanin82/80c14a1da38595350e41 to your computer and use it in GitHub Desktop.
Save ssanin82/80c14a1da38595350e41 to your computer and use it in GitHub Desktop.
from collections import defaultdict
def prime_factors(n):
if n < 2:
return None
d = defaultdict(lambda: 0)
i = 2
while i <= n:
if n % i == 0:
d[i] += 1
n /= i
i = 2
else:
i += 1
return d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment