fix(curriculum): typos in python review and others (#66059)

Co-authored-by: majestic-owl448 <26656284+majestic-owl448@users.noreply.github.com>
This commit is contained in:
Aditya Singh
2026-02-26 13:50:30 +05:30
committed by GitHub
parent 4d3f6b72b9
commit 2ccef21368
10 changed files with 29 additions and 29 deletions

View File

@@ -81,7 +81,7 @@ For example, in a transportation network graph, nodes could be cities and their
**Cyclic graphs** are directed graphs with at least one cycle.
A **cycle** is a path that you can follow through the edges of graph that will take you back to the initial node where you started.
A **cycle** is a path that you can follow through the edges of a graph that will take you back to the initial node where you started.
In this example, we have a directed graph. If you look more closely, you'll notice that it has a cycle. If we start at node B, go to node C, and then to node D, we can go back to node B again through the directed edges.

View File

@@ -255,7 +255,7 @@ The algorithm visited the nodes in this order:
Notice how we start at node A, and then move all the way down the tree to node B, and nodes D and E, before we move up again to node C and then nodes F and G. This is the core principle of depth-first search (DFS), traversing full paths before backtracking and finding other paths.
In this case, we solved this example using a stack. Alternatively, depth-first search (DFS) can be implemented using recursion, where the function processes the current node and then call itself for each of its unvisited neighbors. The function call stack implicitly manages the LIFO (last-in, first-out) order.
In this case, we solved this example using a stack. Alternatively, depth-first search (DFS) can be implemented using recursion, where the function processes the current node and then calls itself for each of its unvisited neighbors. The function call stack implicitly manages the LIFO (last-in, first-out) order.
Both breadth-first search (BFS) and depth-first search (DFS) are essential algorithms for traversing graphs and trees. Breadth-first search (BFS) explores nodes level by level, which is perfect for finding the shortest path in an unweighted graph. On the other hand, depth-first search (DFS) follows one branch as deep as possible before backtracking, which is perfect for solving mazes and detecting cycles. Understanding their pros and cons is helpful for choosing the right one for a particular problem.

View File

@@ -26,7 +26,7 @@ An adjacency matrix is a two-dimensional array in which the rows and columns rep
The values in the matrix represent the edges or connections between the nodes.
For example, if you have a matrix stored in a variable named `matrix`, the value stored at `matrix[i][j]`, where `i` is the row and `j` is the column, represents the edge or connection between nodes `i` and node `j`.
For example, if you have a matrix stored in a variable named `matrix`, the value stored at `matrix[i][j]`, where `i` is the row and `j` is the column, represents the edge or connection between node `i` and node `j`.
The values may have different meanings depending on whether the graph is weighted or unweighted:

View File

@@ -145,7 +145,7 @@ To add elements to the heap, you would call `push()`. This will automatically ad
myHeap.push(9);
```
To get the element with the lowest priority (in this case, the smallest value), you would call `pop()`:
To get the element with the highest priority (in this case, the smallest value), you would call `pop()`:
```js
myHeap.pop();

View File

@@ -81,7 +81,7 @@ For example, in a transportation network graph, nodes could be cities and their
**Cyclic graphs** are directed graphs with at least one cycle.
A **cycle** is a path that you can follow through the edges of graph that will take you back to the initial node where you started.
A **cycle** is a path that you can follow through the edges of a graph that will take you back to the initial node where you started.
In this example, we have a directed graph. If you look more closely, you'll notice that it has a cycle. If we start at node B, go to node C, and then to node D, we can go back to node B again through the directed edges.

View File

@@ -255,7 +255,7 @@ The algorithm visited the nodes in this order:
Notice how we start at node A, and then move all the way down the tree to node B, and nodes D and E, before we move up again to node C and then nodes F and G. This is the core principle of depth-first search (DFS), traversing full paths before backtracking and finding other paths.
In this case, we solved this example using a stack. Alternatively, depth-first search (DFS) can be implemented using recursion, where the function processes the current node and then call itself for each of its unvisited neighbors. The function call stack implicitly manages the LIFO (last-in, first-out) order.
In this case, we solved this example using a stack. Alternatively, depth-first search (DFS) can be implemented using recursion, where the function processes the current node and then calls itself for each of its unvisited neighbors. The function call stack implicitly manages the LIFO (last-in, first-out) order.
Both breadth-first search (BFS) and depth-first search (DFS) are essential algorithms for traversing graphs and trees. Breadth-first search (BFS) explores nodes level by level, which is perfect for finding the shortest path in an unweighted graph. On the other hand, depth-first search (DFS) follows one branch as deep as possible before backtracking, which is perfect for solving mazes and detecting cycles. Understanding their pros and cons is helpful for choosing the right one for a particular problem.

View File

@@ -26,7 +26,7 @@ An adjacency matrix is a two-dimensional list in which the rows and columns repr
The values in the matrix represent the edges or connections between the nodes.
For example, if you have a matrix stored in a variable named `matrix`, the value stored at `matrix[i][j]`, where `i` is the row and `j` is the column, represents the edge or connection between nodes `i` and node `j`.
For example, if you have a matrix stored in a variable named `matrix`, the value stored at `matrix[i][j]`, where `i` is the row and `j` is the column, represents the edge or connection between node `i` and node `j`.
The values may have different meanings depending on whether the graph is weighted or unweighted:

View File

@@ -72,7 +72,7 @@ To add elements to the heap, you would call `heappush()`, passing the name of th
heapq.heappush(my_heap, 9)
```
To get the element with the lowest priority (in this case, the smallest value), you would call `heappop()`:
To get the element with the highest priority (in this case, the smallest value), you would call `heappop()`:
```python
heapq.heappop(my_heap)
@@ -86,7 +86,7 @@ This is more efficient than calling them in a sequence separately, especially wh
heapq.heappushpop(my_heap, 15)
```
If you already have a list and you want to transform it into a heap, you could call `heapify()`, passing the heap as argument:
If you already have a list and you want to transform it into a heap, you could call `heapify()`, passing the list as argument:
```python
heapq.heapify(my_heap)

View File

@@ -31,7 +31,7 @@ age = 25
- Variable names can only contain alphanumeric characters (a-z, A-Z, 0-9) and underscores (_).
- Variable names are case-sensitive — `age`, `Age`, and `AGE` are all considered unique.
- Variable names cannot be one of Pythons reserved keywords such as `if`, `class`, or `def`.
- Variables names with multiple words are separated by underscores. Ex. `snake_case`.
- Variable names with multiple words are separated by underscores. E.g., `snake_case`.
## Comments
@@ -213,7 +213,7 @@ print(greeting) # My name is Jessica.
str[start:stop:step]
```
The start position represents the index where the extraction should begin. The stop position is where the slice should end. This position is non inclusive. The step position represents the interval to increment for the slicing. Here are some examples:
The start position represents the index where the extraction should begin. The stop position is where the slice should end. This position is non-inclusive. The step position represents the interval to increment for the slicing. Here are some examples:
```py
message = 'Python is fun!'
@@ -441,7 +441,7 @@ int_2 = 2
print(int_1 ** int_2) # 16
```
- **`float()` Function**: You can use this function to convert an integer to float.
- **`float()` Function**: You can use this function to convert an integer to a float.
```py
num = 4
@@ -449,7 +449,7 @@ num = 4
print(float(num)) # 4.0
```
- **`int()` Function**: You can use this function to convert an float to an integer.
- **`int()` Function**: You can use this function to convert a float to an integer.
```py
num = 4.0
@@ -558,7 +558,7 @@ There are other augmented assignment operators too, like those for bitwise opera
## Working with Functions
- **Definition**: Functions are reusable pieces of code that take inputs (arguments) and returns an output. To call a function, you need to reference the function name followed by a set of parenthesis:
- **Definition**: Functions are reusable pieces of code that take inputs (arguments) and return an output. To call a function, you need to reference the function name followed by a set of parenthesis:
```py
# Defining a function
@@ -800,7 +800,7 @@ else:
print('You are not eligible to vote')
```
- **`or` Operator**: This operator returns the first operand if it is truthy, otherwise, it returns the second operand. An or expression results in a truthy value if at least one operand is truthy. Here is an example:
- **`or` Operator**: This operator returns the first operand if it is truthy, otherwise, it returns the second operand. An `or` expression results in a truthy value if at least one operand is truthy. Here is an example:
```py
age = 19
@@ -821,7 +821,7 @@ else:
print('You are not eligible for a student discount')
```
- **Short-circuiting**: The `and` and `or` operators are known as a short-circuit operators. Short-circuiting means Python checks values from left to right and stops as soon as it determines the final result.
- **Short-circuiting**: The `and` and `or` operators are known as short-circuit operators. Short-circuiting means Python checks values from left to right and stops as soon as it determines the final result.
- **`not` Operator**: This operator takes a single operand and inverts its boolean value. It converts truthy values to `False` and falsy values to `True`. Unlike the previous operators we looked at, `not` always returns `True` or `False`. Here are some examples:
```py
@@ -1193,14 +1193,14 @@ programming_languages = ('Rust', 'Java', 'Python', 'C++', 'Rust')
programming_languages.count('Rust') # 2
```
- If the specified item in the `count()` function is not present at all in the tuple, then the return value will be `0`:
- If the specified item in the `count()` method is not present at all in the tuple, then the return value will be `0`:
```py
programming_languages = ('Rust', 'Java', 'Python', 'C++', 'Rust')
programming_languages.count('JavaScript') # 0
```
- If no arguments are passed to the `count()` function, then Python will return a `TypeError`.
- If no arguments are passed to the `count()` method, then Python will return a `TypeError`.
- **index()**: Used to find the index where a particular item is present in the tuple. Here is an example of using the `index()` method to find the index for the language `'Java'`:
@@ -1386,7 +1386,7 @@ for word in words:
range(start, stop, step)
```
- The required `stop` argument is an integer(non-inclusive) that represents the end point for the sequence of numbers being generated. Here is an example of using the `range()` function:
- The required `stop` argument is an integer (non-inclusive) that represents the end point for the sequence of numbers being generated. Here is an example of using the `range()` function:
```py
for num in range(3):
@@ -1480,7 +1480,7 @@ ID: 4
```
## List comprehensions in Python
## List Comprehensions in Python
- **Definition**: List comprehension allows you to create a new list in a single line by combining the loop and the condition directly within square brackets. This makes the code shorter and often easier to read.
@@ -1489,7 +1489,7 @@ even_numbers = [num for num in range(21) if num % 2 == 0]
print(even_numbers)
```
## Iterable methods
## Iterable Functions
- **`filter()`**: Used to filter elements from an iterable based on a condition. It returns an iterator that contains only the elements that satisfy the condition. Here is an example of creating a new list of just words longer than four characters:
@@ -1539,7 +1539,7 @@ total = sum(numbers, start=10) # keyword argument
print(total) # 60
```
## Lambda functions
## Lambda Functions
- **Definition**: A lambda function in Python is a concise way to create a function without a name (an anonymous function).
- Lambda functions are often used as an argument to another function. Here is an example of a lambda function:
@@ -1821,7 +1821,7 @@ your_set = {2, 3, 4, 6}
my_set & your_set # {2, 3, 4}
```
- **Difference Operator (`-`)**: The difference operator `-` returns a new set with the elements of the first set that are not in the other sets.
- **Difference Operator (`-`)**: The difference operator `-` returns a new set with the elements of the first set that are not in the other set.
```python
my_set = {1, 2, 3, 4, 5}
@@ -1951,7 +1951,7 @@ if __name__ == '__main__':
- **SyntaxError**: The error Python raises when your code does not follow its syntax rules. For example, the code `print("Hello there"` will lead to a syntax error with the message, `SyntaxError: '(' was never closed`, because the code is missing a closing parenthesis.
- **NameError**: Python raises a `NameError` when you try to access a variable or function you have not defined. For instance, if you have the line `print(username)` in your code without having a `username` variable defined first, you will get a name error with the message `NameError: name 'username' is not defined`.
- **TypeError**: This is the error Python throws when you perform an operation on two or more incompatible data types. For example, if you try to add a string to a number, you'll get the error `TypeError: can only concatenate str (not "int") to str`.
- **IndexError**: You'll get an `IndexError` if you access an index that does not exist in a list or other sequences like tuple and string. For example, in a `Hello world` string, the index of the last character is `11`. If you go ahead and access a character this way, `greet = "hello world"; print(greet[12])`, you'll get an error with the message `IndexError: string index out of range`.
- **IndexError**: You'll get an `IndexError` if you access an index that does not exist in a list or other sequences like tuple and string. For example, in a `Hello world` string, the index of the last character is `10`. If you go ahead and access a character this way, `greet = "hello world"; print(greet[11])`, you'll get an error with the message `IndexError: string index out of range`.
- **AttributeError**: Python raises this error when you try to use a method or property that does not exist in an object of that type. For example, calling `.append()` on a string like `"hello".append("!")` will lead to an error with the message `AttributeError: 'str' object has no attribute 'append'`.
## Good Debugging Techniques in Python
@@ -1983,7 +1983,7 @@ if __name__ == '__main__':
# You cannot divide by zero! prints when you enter 0
except ValueError:
print('Please enter a valid number!')
# Please enter a valid number! prints when you enter a string
# Please enter a valid number! prints when you don't enter an integer
```
- **`else` and `finally`**: These blocks extend `try...except`. If no exception occurs, the `else` block runs. The `finally` block always runs regardless of errors.
@@ -2190,7 +2190,7 @@ print(str(book1)) # 'Built Wealth Like a Boss' has 420 pages
- **Calling dunder methods indirectly**: You don't need to call dunder methods directly. Instead, Python automatically calls them when certain actions happen. These operations include:
- **arithmetic operations like addition, subtraction, multiplication, division, and others**. In addition, `__add__()` is called, `__sub__()` for subtraction, `__mul__()` for multiplication, and `__truediv__()` for division.
- **arithmetic operations like addition, subtraction, multiplication, division, and others**. `__add__()` is called for addition, `__sub__()` for subtraction, `__mul__()` for multiplication, and `__truediv__()` for division.
- **string operations like concatenation, repetition, formatting, and conversion to text**. `__add__()` is called for concatenation, `__mul__()` for repetition, `__format__()` for formatting, `__str__()` and `__repr__()` for text conversion, and so on.
@@ -2240,7 +2240,7 @@ print('Laptop' in cart) # True
## What is Object-Oriented Programming?
- **Object-oriented programming**: A programming style in which developers treat everything in their code like a real-world object. It is popularly called OOP. The four key principles that help you organize and manage code effectively are **encapsulation**, **inheritance**, **polymorphism**, and **abstraction**
- **Classes**: The blueprint for creating objects. Every single object created from a class has attributes that define data and methods that determine the behaviors of the objects.
- **Classes**: The blueprint for creating objects. Every single object created from a class has attributes that define data and methods that determine the behaviors of the object.
## What is Encapsulation?
@@ -2738,7 +2738,7 @@ A graph is a set of nodes (vertices) connected by edges (connections). Each node
- Directed: edges have a direction (from one node to another), often represented with straight lines and arrows.
- Undirected: edges have no direction, represented with simple lines.
- Vertex: each node is associated to a label or identifier.
- Vertex: each node is associated with a label or identifier.
- Cyclic: contains cycles (a path that starts and ends at the same node).
- Acyclic (DAG): does not contain cycles.
- Edge labeled: each edge has a label usually drawn next to corresponding edge.

View File

@@ -11,7 +11,7 @@ When you find a shorter path to a node, you also need to update the actual path
Inside the same conditional block, update the `paths` list at the neighbor's index to reflect the new, shorter path.
You should assign `paths[node_no]` to be the current path to the `current` node, with the `node_no` (the neighbor) added at the end.
You should update `paths[node_no]` to be the current path to the `current` node, with the `node_no` (the neighbor) added at the end.
# --hints--