DEV Community

Discussion on: Find Factors of A number

Collapse
 
curtisfenner profile image
Curtis Fenner

You can make this really concise with list comprehension:

def factors_of(n):
    return [k for k in range(1, n+1) if n % k == 0]
Collapse
 
nciphalucas profile image
Vuyisile Lucas Ncipha • Edited

YES, But a lot of people are new to python programming, if that was not the case I would have used lambda function to solve this.

   factors_of = lambda number: [k for k in range(1, number+1) if number%k==0]