Skip to content

Commit

Permalink
[Sieve]: Update content.md for Comprehension Approach (#3865)
Browse files Browse the repository at this point in the history
Added language about the disallowed `%` operator to the Comprehensions approach.
  • Loading branch information
BethanyG authored Feb 14, 2025
1 parent c99a16e commit 664f1db
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def primes(limit):
if all(number % divisor != 0 for divisor in range(2, number))]
```

This second example using a `list-comprehension` with `all()` is certainly concise and _relatively_ readable, but the performance is again quite poor.
This second example using a `list-comprehension` with `all()` is certainly concise and _relatively_ readable, but it uses **`%`** (_which the instructions ask you not to use_) and the performance is again quite poor.


This is not quite a fully nested loop (_there is a short-circuit when `all()` evaluates to `False`_), but it is by no means "performant".
In this case, scaling with input size is intermediate between linear and quadratic, so not quite as bad as the first example.
Expand Down

0 comments on commit 664f1db

Please sign in to comment.