Skip to content

Commit

Permalink
Update mentoring.md (#2350)
Browse files Browse the repository at this point in the history
I have corrected some spelling mistakes.
  • Loading branch information
thomasantony12 authored Jun 8, 2024
1 parent 57b0d21 commit 5854d9a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tracks/python/exercises/perfect-numbers/mentoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A simple optimization is to use `range(1, number // 2 + 1)` as the `for` loop `i
This halves the complexity of the solution.

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`.
This solution is longer and more involved but significantly faster, reducing the complextiy from `O(n)` (_linear_) to `O(sqrt(n))` (_square root_).
This solution is longer and more involved but significantly faster, reducing the complexity from `O(n)` (_linear_) to `O(sqrt(n))` (_square root_).

```python
def classify(number):
Expand All @@ -49,5 +49,5 @@ def classify(number):

Students unfamiliar with `generator expressions` might write: `aliquot = sum([item for item in range(1, number) if number % item == 0])`.
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.
This is inefficent for both memory and processing time.
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.
This is inefficient for both memory and processing time.
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 comments on commit 5854d9a

Please sign in to comment.