Created
February 28, 2014 19:39
-
-
Save rahul8590/9278243 to your computer and use it in GitHub Desktop.
Easiest Way to factorize in Python
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
''' | |
divmod() function is a handy tool in such cases. | |
>>> divmod(10,2) | |
(5, 0) | |
''' | |
r = set() | |
def factorize(n): | |
for i in range(1,int(n ** 0.5) + 1 ): | |
div,mod = divmod(n,i) | |
if mod == 0: | |
r |= {i,div} | |
return r | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment