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: episodes/optimisation-using-python.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,8 +104,8 @@ It is often best to tell the interpreter/library at a high level *what you want*
104
104
## Example: Searching an element in a list
105
105
106
106
A simple example of this is performing a linear search on a list. (Though as we’ll see in the next section, this isn't the most efficient approach!)
107
-
In the following example, we create a list of 2500 integers in the (inclusive-exclusive) range `[0, 5000)`.
108
-
The goal is to search for all even numbers within that range.
107
+
In the following example, we create a list of 2500 random integers in the (inclusive-exclusive) range `[0, 5000)`.
108
+
The goal is to count how many even numbers are in the list.
109
109
110
110
The function `manualSearch()` manually iterates through the list (`ls`) and checks each individual item using Python code. On the other hand, `operatorSearch()` uses the `in` operator to perform each search, which allows CPython to implement the inner loop in its C back-end.
111
111
@@ -118,18 +118,18 @@ M = 2 # N*M == Range over which the elements span
118
118
ls = [random.randint(0, int(N*M)) for i inrange(N)]
0 commit comments