Skip to content

Instantly share code, notes, and snippets.

@gcrsaldanha
Created December 31, 2018 01:13
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 gcrsaldanha/92622be3ed062b0fe4fc41ba43ffe774 to your computer and use it in GitHub Desktop.
Save gcrsaldanha/92622be3ed062b0fe4fc41ba43ffe774 to your computer and use it in GitHub Desktop.
Simple method to find the factors of a given number (computationally expensive)
def find_factors(number):
factors = []
for factor in range(1, number + 1): # makes range go from 1 to number (inclusive)
if number % factor == 0:
factors.append(factor)
return factors
# Or by using list comprehensions
def find_factors_comprehesion(number):
return [factor for factor in range(1, number + 1) if number % factor == 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment