Skip to content
Open
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
12 changes: 12 additions & 0 deletions list_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Optional


def find_max(numbers: list[int]) -> Optional[int]:
if not numbers:
return None
return max(numbers)
Comment on lines +4 to +7

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstrings — required by org guidelines.

All public functions must have docstrings describing what the function does, its parameters, and its return value. Both find_max() and flatten() are missing them.

Suggested change
def find_max(numbers: list[int]) -> Optional[int]:
if not numbers:
return None
return max(numbers)
def find_max(numbers: list[int]) -> Optional[int]:
"""Return the maximum value in a list of integers, or None if the list is empty.
Args:
numbers: A list of integers.
Returns:
The maximum integer, or None if the list is empty.
"""
if not numbers:
return None
return max(numbers)
  • Mark as noise



def flatten(nested: list[list]) -> list:
return [item for sublist in nested for item in sublist]
Comment on lines +10 to +11

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring — required by org guidelines. Also, the type hint list[list] implies every element must itself be a list, but the implementation silently skips or raises TypeError if a sublist contains non-iterable items (e.g. [[1, 2], 3] raises TypeError: 'int' object is not iterable with no clear message).

Add a docstring and consider whether the function should validate its input or document the assumption explicitly.

Suggested change
def flatten(nested: list[list]) -> list:
return [item for sublist in nested for item in sublist]
def flatten(nested: list[list]) -> list:
"""Flatten a list of lists into a single list.
Args:
nested: A list where each element is itself a list.
Returns:
A single flat list containing all items from the sublists.
Raises:
TypeError: If any element of `nested` is not iterable.
"""
return [item for sublist in nested for item in sublist]
  • Mark as noise


Loading