Skip to content

Commit cecf43d

Browse files
cclaussgithub-actions
andauthored
Pyupgrade to Python 3.9 (#4718)
* Pyupgrade to Python 3.9 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 5d5831b commit cecf43d

File tree

142 files changed

+523
-530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+523
-530
lines changed

DIRECTORY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@
545545
## Other
546546
* [Activity Selection](https://github.com/TheAlgorithms/Python/blob/master/other/activity_selection.py)
547547
* [Date To Weekday](https://github.com/TheAlgorithms/Python/blob/master/other/date_to_weekday.py)
548-
* [Davis–Putnam–Logemann–Loveland](https://github.com/TheAlgorithms/Python/blob/master/other/davis–putnam–logemann–loveland.py)
548+
* [Davisb Putnamb Logemannb Loveland](https://github.com/TheAlgorithms/Python/blob/master/other/davisb_putnamb_logemannb_loveland.py)
549549
* [Dijkstra Bankers Algorithm](https://github.com/TheAlgorithms/Python/blob/master/other/dijkstra_bankers_algorithm.py)
550550
* [Doomsday](https://github.com/TheAlgorithms/Python/blob/master/other/doomsday.py)
551551
* [Fischer Yates Shuffle](https://github.com/TheAlgorithms/Python/blob/master/other/fischer_yates_shuffle.py)
@@ -860,6 +860,7 @@
860860
* [Counting Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/counting_sort.py)
861861
* [Cycle Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/cycle_sort.py)
862862
* [Double Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/double_sort.py)
863+
* [Dutch National Flag Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/dutch_national_flag_sort.py)
863864
* [Exchange Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/exchange_sort.py)
864865
* [External Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/external_sort.py)
865866
* [Gnome Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/gnome_sort.py)

arithmetic_analysis/in_static_equilibrium.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""
22
Checks if a system of forces is in static equilibrium.
33
"""
4-
from typing import List
4+
from __future__ import annotations
55

66
from numpy import array, cos, cross, ndarray, radians, sin
77

88

99
def polar_force(
1010
magnitude: float, angle: float, radian_mode: bool = False
11-
) -> List[float]:
11+
) -> list[float]:
1212
"""
1313
Resolves force along rectangular components.
1414
(force, angle) => (force_x, force_y)

arithmetic_analysis/lu_decomposition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
Reference:
44
- https://en.wikipedia.org/wiki/LU_decomposition
55
"""
6-
from typing import Tuple
6+
from __future__ import annotations
77

88
import numpy as np
99

1010

11-
def lower_upper_decomposition(table: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
11+
def lower_upper_decomposition(table: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
1212
"""Lower-Upper (LU) Decomposition
1313
1414
Example:

arithmetic_analysis/newton_forward_interpolation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# https://www.geeksforgeeks.org/newton-forward-backward-interpolation/
2+
from __future__ import annotations
23

34
import math
4-
from typing import List
55

66

77
# for calculating u value
@@ -22,7 +22,7 @@ def ucal(u: float, p: int) -> float:
2222

2323
def main() -> None:
2424
n = int(input("enter the numbers of values: "))
25-
y: List[List[float]] = []
25+
y: list[list[float]] = []
2626
for i in range(n):
2727
y.append([])
2828
for i in range(n):

arithmetic_analysis/newton_raphson.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
# Author: Syed Haseeb Shah (github.com/QuantumNovice)
33
# The Newton-Raphson method (also known as Newton's method) is a way to
44
# quickly find a good approximation for the root of a real-valued function
5+
from __future__ import annotations
6+
57
from decimal import Decimal
68
from math import * # noqa: F401, F403
7-
from typing import Union
89

910
from sympy import diff
1011

1112

1213
def newton_raphson(
13-
func: str, a: Union[float, Decimal], precision: float = 10 ** -10
14+
func: str, a: float | Decimal, precision: float = 10 ** -10
1415
) -> float:
1516
"""Finds root from the point 'a' onwards by Newton-Raphson method
1617
>>> newton_raphson("sin(x)", 2)

backtracking/all_combinations.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
numbers out of 1 ... n. We use backtracking to solve this problem.
44
Time complexity: O(C(n,k)) which is O(n choose k) = O((n!/(k! * (n - k)!)))
55
"""
6-
from typing import List
6+
from __future__ import annotations
77

88

9-
def generate_all_combinations(n: int, k: int) -> List[List[int]]:
9+
def generate_all_combinations(n: int, k: int) -> list[list[int]]:
1010
"""
1111
>>> generate_all_combinations(n=4, k=2)
1212
[[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
1313
"""
1414

15-
result: List[List[int]] = []
15+
result: list[list[int]] = []
1616
create_all_state(1, n, k, [], result)
1717
return result
1818

@@ -21,8 +21,8 @@ def create_all_state(
2121
increment: int,
2222
total_number: int,
2323
level: int,
24-
current_list: List[int],
25-
total_list: List[List[int]],
24+
current_list: list[int],
25+
total_list: list[list[int]],
2626
) -> None:
2727
if level == 0:
2828
total_list.append(current_list[:])
@@ -34,7 +34,7 @@ def create_all_state(
3434
current_list.pop()
3535

3636

37-
def print_all_state(total_list: List[List[int]]) -> None:
37+
def print_all_state(total_list: list[list[int]]) -> None:
3838
for i in total_list:
3939
print(*i)
4040

backtracking/all_permutations.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
Time complexity: O(n! * n),
66
where n denotes the length of the given sequence.
77
"""
8-
from typing import List, Union
8+
from __future__ import annotations
99

1010

11-
def generate_all_permutations(sequence: List[Union[int, str]]) -> None:
11+
def generate_all_permutations(sequence: list[int | str]) -> None:
1212
create_state_space_tree(sequence, [], 0, [0 for i in range(len(sequence))])
1313

1414

1515
def create_state_space_tree(
16-
sequence: List[Union[int, str]],
17-
current_sequence: List[Union[int, str]],
16+
sequence: list[int | str],
17+
current_sequence: list[int | str],
1818
index: int,
19-
index_used: List[int],
19+
index_used: list[int],
2020
) -> None:
2121
"""
2222
Creates a state space tree to iterate through each branch using DFS.
@@ -44,8 +44,8 @@ def create_state_space_tree(
4444
sequence = list(map(int, input().split()))
4545
"""
4646

47-
sequence: List[Union[int, str]] = [3, 1, 2, 4]
47+
sequence: list[int | str] = [3, 1, 2, 4]
4848
generate_all_permutations(sequence)
4949

50-
sequence_2: List[Union[int, str]] = ["A", "B", "C"]
50+
sequence_2: list[int | str] = ["A", "B", "C"]
5151
generate_all_permutations(sequence_2)

backtracking/all_subsequences.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
Time complexity: O(2^n),
66
where n denotes the length of the given sequence.
77
"""
8-
from typing import Any, List
8+
from __future__ import annotations
99

10+
from typing import Any
1011

11-
def generate_all_subsequences(sequence: List[Any]) -> None:
12+
13+
def generate_all_subsequences(sequence: list[Any]) -> None:
1214
create_state_space_tree(sequence, [], 0)
1315

1416

1517
def create_state_space_tree(
16-
sequence: List[Any], current_subsequence: List[Any], index: int
18+
sequence: list[Any], current_subsequence: list[Any], index: int
1719
) -> None:
1820
"""
1921
Creates a state space tree to iterate through each branch using DFS.
@@ -32,7 +34,7 @@ def create_state_space_tree(
3234

3335

3436
if __name__ == "__main__":
35-
seq: List[Any] = [3, 1, 2, 4]
37+
seq: list[Any] = [3, 1, 2, 4]
3638
generate_all_subsequences(seq)
3739

3840
seq.clear()

backtracking/coloring.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
66
Wikipedia: https://en.wikipedia.org/wiki/Graph_coloring
77
"""
8-
from typing import List
98

109

1110
def valid_coloring(
12-
neighbours: List[int], colored_vertices: List[int], color: int
11+
neighbours: list[int], colored_vertices: list[int], color: int
1312
) -> bool:
1413
"""
1514
For each neighbour check if coloring constraint is satisfied
@@ -35,7 +34,7 @@ def valid_coloring(
3534

3635

3736
def util_color(
38-
graph: List[List[int]], max_colors: int, colored_vertices: List[int], index: int
37+
graph: list[list[int]], max_colors: int, colored_vertices: list[int], index: int
3938
) -> bool:
4039
"""
4140
Pseudo-Code
@@ -86,7 +85,7 @@ def util_color(
8685
return False
8786

8887

89-
def color(graph: List[List[int]], max_colors: int) -> List[int]:
88+
def color(graph: list[list[int]], max_colors: int) -> list[int]:
9089
"""
9190
Wrapper function to call subroutine called util_color
9291
which will either return True or False.

backtracking/hamiltonian_cycle.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
77
Wikipedia: https://en.wikipedia.org/wiki/Hamiltonian_path
88
"""
9-
from typing import List
109

1110

1211
def valid_connection(
13-
graph: List[List[int]], next_ver: int, curr_ind: int, path: List[int]
12+
graph: list[list[int]], next_ver: int, curr_ind: int, path: list[int]
1413
) -> bool:
1514
"""
1615
Checks whether it is possible to add next into path by validating 2 statements
@@ -47,7 +46,7 @@ def valid_connection(
4746
return not any(vertex == next_ver for vertex in path)
4847

4948

50-
def util_hamilton_cycle(graph: List[List[int]], path: List[int], curr_ind: int) -> bool:
49+
def util_hamilton_cycle(graph: list[list[int]], path: list[int], curr_ind: int) -> bool:
5150
"""
5251
Pseudo-Code
5352
Base Case:
@@ -108,7 +107,7 @@ def util_hamilton_cycle(graph: List[List[int]], path: List[int], curr_ind: int)
108107
return False
109108

110109

111-
def hamilton_cycle(graph: List[List[int]], start_index: int = 0) -> List[int]:
110+
def hamilton_cycle(graph: list[list[int]], start_index: int = 0) -> list[int]:
112111
r"""
113112
Wrapper function to call subroutine called util_hamilton_cycle,
114113
which will either return array of vertices indicating hamiltonian cycle

0 commit comments

Comments
 (0)