Skip to main content
Code Review

Return to Revisions

4 of 5
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/

The first thing I spotted when I saw your code was the indentation. In python, you should use 4 spaces per indentation level. More, you should have 2 new lines between your methods and keep your lines no longer than 120 characters (in PEP 8 - which is the official python style-guide, the limit is of 79 characters but I like to stick with InteliJ's recommendation).

More, based on ChatterOne's answer I'd rewrite his first two functions as follows:

def get_divisors_count(number):
 """What does this function do?"""
 return len([divisor for divisor in range(1, number + 1) if (number % divisor) == 0])
def get_divisors_range(number_range):
 """What does this function do?"""
 return {number: get_divisors_count(number) for number in range(1, number_range)}

In the first function I've used list comprehension and in the second one dictionary comprehension. You can read more about them (and their advantages) here and here

Last but not least, you should definitely add docstrings to your functions to describe their functionality.

Another thing you might do is adding the if __name__ == '__main__' guard.

Grajdeanu Alex
  • 9.3k
  • 4
  • 32
  • 71
default

AltStyle によって変換されたページ (->オリジナル) /