Created
April 2, 2015 05:13
-
-
Save pscollins/6d1bb9b7b2145e43aa25 to your computer and use it in GitHub Desktop.
Python prime factorization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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