Skip to content

Instantly share code, notes, and snippets.

@pscollins
Created April 2, 2015 05:13
Show Gist options
  • Save pscollins/6d1bb9b7b2145e43aa25 to your computer and use it in GitHub Desktop.
Save pscollins/6d1bb9b7b2145e43aa25 to your computer and use it in GitHub Desktop.
Python prime factorization
def factors(n):
app = [n] if n != 1 else []
ans = set(chain(app, *((i, n//i) for i in range(2, int(sqrt(n) + 1))
if not n % i)))
return ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment