You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tracks/python/exercises/perfect-numbers/mentoring.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ A simple optimization is to use `range(1, number // 2 + 1)` as the `for` loop `i
29
29
This halves the complexity of the solution.
30
30
31
31
For a more efficient solution, one can compute all the factors by using the smaller `range(1, int(math.sqrt(number)) + 1)` as the `iterable`.
32
-
This solution is longer and more involved but significantly faster, reducing the complextiy from `O(n)` (_linear_) to `O(sqrt(n))` (_square root_).
32
+
This solution is longer and more involved but significantly faster, reducing the complexity from `O(n)` (_linear_) to `O(sqrt(n))` (_square root_).
33
33
34
34
```python
35
35
defclassify(number):
@@ -49,5 +49,5 @@ def classify(number):
49
49
50
50
Students unfamiliar with `generator expressions` might write: `aliquot = sum([item for item in range(1, number) if number % item == 0])`.
51
51
Note this first creates a `list` of factors in memory by iterating over the entire range, then iterates once more over the `list` to `sum()` its values.
52
-
This is inefficent for both memory and processing time.
53
-
Dropping the `[]` drops `list` creation and allows `sum()` to lazily process a `generator expression`, wich only requires a single iteration and a smaller memory footprint.
52
+
This is inefficient for both memory and processing time.
53
+
Dropping the `[]` drops `list` creation and allows `sum()` to lazily process a `generator expression`, which only requires a single iteration and a smaller memory footprint.
0 commit comments