diff --git a/data_structures/hashing/hash_table_with_linked_list.py b/data_structures/hashing/hash_table_with_linked_list.py index f404c5251246..c8dffa30b8e8 100644 --- a/data_structures/hashing/hash_table_with_linked_list.py +++ b/data_structures/hashing/hash_table_with_linked_list.py @@ -8,7 +8,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def _set_value(self, key, data): - self.values[key] = deque([]) if self.values[key] is None else self.values[key] + self.values[key] = deque() if self.values[key] is None else self.values[key] self.values[key].appendleft(data) self._keys[key] = self.values[key] diff --git a/machine_learning/linear_discriminant_analysis.py b/machine_learning/linear_discriminant_analysis.py index 8528ccbbae51..af5248c4dbc4 100644 --- a/machine_learning/linear_discriminant_analysis.py +++ b/machine_learning/linear_discriminant_analysis.py @@ -252,7 +252,7 @@ def accuracy(actual_y: list, predicted_y: list) -> float: num = TypeVar("num") -def valid_input( +def valid_input[num]( input_type: Callable[[object], num], # Usually float or int input_msg: str, err_msg: str, diff --git a/maths/volume.py b/maths/volume.py index 1715c9c300d5..f48d388b423e 100644 --- a/maths/volume.py +++ b/maths/volume.py @@ -510,6 +510,32 @@ def vol_torus(torus_radius: float, tube_radius: float) -> float: return 2 * pow(pi, 2) * torus_radius * pow(tube_radius, 2) +def vol_octahedron(oct_side: float) -> float: + """ + | Calculate the Volume of an Octahedron. + | Wikipedia reference: https://en.wikipedia.org/wiki/Regular_octahedron + + >>> from math import isclose + >>> isclose(vol_octahedron(2.5), 7.36569563735987) + True + >>> isclose(vol_octahedron(10), 471.40452079103168) + True + >>> isclose(vol_octahedron(5), 58.92556509887896) + True + >>> isclose(vol_octahedron(3.5), 20.21146882891548) + True + >>> vol_octahedron(0) + 0.0 + >>> vol_octahedron(-1) + Traceback (most recent call last): + ... + ValueError: vol_octahedron() only accepts non-negative values + """ + if oct_side < 0: + raise ValueError("vol_octahedron() only accepts non-negative values") + return oct_side**3 * 2**0.5 / 3 + + def vol_icosahedron(tri_side: float) -> float: """ | Calculate the Volume of an Icosahedron. @@ -560,6 +586,7 @@ def main(): print( f"Hollow Circular Cylinder: {vol_hollow_circular_cylinder(1, 2, 3) = }" ) # ~= 28.3 + print(f"Octahedron: {vol_octahedron(2.5) = }") # ~=7.37 print(f"Icosahedron: {vol_icosahedron(2.5) = }") # ~=34.09 diff --git a/searches/jump_search.py b/searches/jump_search.py index e72d85e8a868..b443d09283b0 100644 --- a/searches/jump_search.py +++ b/searches/jump_search.py @@ -20,7 +20,7 @@ def __lt__(self, other: Any, /) -> bool: ... T = TypeVar("T", bound=Comparable) -def jump_search(arr: Sequence[T], item: T) -> int: +def jump_search[T: Comparable](arr: Sequence[T], item: T) -> int: """ Python implementation of the jump search algorithm. Return the index if the `item` is found, otherwise return -1.