Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data_structures/hashing/hash_table_with_linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion machine_learning/linear_discriminant_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions maths/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion searches/jump_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down