Skip to content
Closed
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
7 changes: 6 additions & 1 deletion computer_vision/mean_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ def mean_threshold(image: Image.Image) -> Image.Image:
height, width = image.size
mean = 0
pixels = image.load()
if pixels is None:
raise ValueError("image does not support pixel access")
for i in range(width):
for j in range(height):
pixel = pixels[j, i]
assert isinstance(pixel, int | float) # grayscale images only
mean += pixel
mean //= width * height

for j in range(width):
for i in range(height):
pixels[i, j] = 255 if pixels[i, j] > mean else 0
pixel = pixels[i, j]
assert isinstance(pixel, int | float) # grayscale images only
pixels[i, j] = 255 if pixel > mean else 0
return image


Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ rules.not-subscriptable = "ignore"
rules.parameter-already-assigned = "ignore"
rules.unresolved-attribute = "ignore"
rules.unresolved-import = "ignore"
rules.unsupported-operator = "ignore"

[tool.pytest]
ini_options.addopts = [
Expand Down
1 change: 1 addition & 0 deletions sorts/iterative_merge_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

class Comparable(Protocol):
def __lt__(self, other: Any, /) -> bool: ...
def __le__(self, other: Any, /) -> bool: ...


def merge[T: Comparable](input_list: list[T], low: int, mid: int, high: int) -> list[T]:
Expand Down
1 change: 1 addition & 0 deletions sorts/quick_sort_3_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class Comparable(Protocol):
def __lt__(self, other: Any, /) -> bool: ...
def __ge__(self, other: Any, /) -> bool: ...


def quick_sort_3partition[T: Comparable](
Expand Down
1 change: 1 addition & 0 deletions sorts/recursive_quick_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class Comparable(Protocol):
def __ge__(self, other: Any, /) -> bool: ...
def __gt__(self, other: Any, /) -> bool: ...
def __le__(self, other: Any, /) -> bool: ...


Expand Down
2 changes: 1 addition & 1 deletion web_programming/get_amazon_product_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_amazon_product_data(product: str = "laptop") -> DataFrame:
):
try:
product_title = item.h2.text
product_link = "https://www.amazon.in/" + item.h2.a["href"]
product_link = f"https://www.amazon.in/{item.h2.a['href']}"
product_price = item.find("span", attrs={"class": "a-offscreen"}).text
try:
product_rating = item.find("span", attrs={"class": "a-icon-alt"}).text
Expand Down
Loading