Skip to content

Instantly share code, notes, and snippets.

@rahul8590
Created February 28, 2014 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahul8590/9278243 to your computer and use it in GitHub Desktop.
Save rahul8590/9278243 to your computer and use it in GitHub Desktop.
Easiest Way to factorize in Python
'''
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