From c9b1bb41397a037d255316c74718320626182e3d Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 12 Oct 2025 12:27:10 -0700 Subject: [PATCH 1/3] Update diamond.py --- diamond/diamond.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diamond/diamond.py b/diamond/diamond.py index 0fdf4fe..8a39d1a 100644 --- a/diamond/diamond.py +++ b/diamond/diamond.py @@ -32,7 +32,8 @@ def rows(letter: str) -> list: result.append(spaces + char + spaces) else: middle: str = " " * (row_length - 2 - (len(spaces) * 2)) - # All rows, except the first and last, have exactly two identical letters. + # All rows, except the first and last, + # have exactly two identical letters. result.append(spaces + char + middle + char + spaces) # Mirror the list: the bottom half has the letters in descending order. result = result + result[::-1][1:] From ed0afece4b71b748e7fec62273667f58e7f761df Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 12 Oct 2025 12:32:48 -0700 Subject: [PATCH 2/3] Update diamond.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add type hint for the return: -> list[str] to make it explicit. In the middle calculation, len(spaces) could be avoided since spaces is a str of known length—use (letter_index - i) * 2 directly for tiny perf gain, but it's negligible. Consider adding a check for letter == 'A' early to skip the loop if desired, but the current loop handles it fine. --- diamond/diamond.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/diamond/diamond.py b/diamond/diamond.py index 8a39d1a..747c256 100644 --- a/diamond/diamond.py +++ b/diamond/diamond.py @@ -9,7 +9,7 @@ CHARS: str = string.ascii_uppercase -def rows(letter: str) -> list: +def rows(letter: str) -> list[str]: """ Return the diamond rows from 'A' to ``letter``. @@ -26,12 +26,13 @@ def rows(letter: str) -> list: for i, char in enumerate(CHARS[: letter_index + 1]): # All rows have as many trailing spaces as leading spaces. - spaces: str = " " * (letter_index - i) + spaces_length: int = letter_index - i + spaces: str = " " * spaces_length # The first/last row contains one 'A'. - if i == 0: + if char == "A": result.append(spaces + char + spaces) else: - middle: str = " " * (row_length - 2 - (len(spaces) * 2)) + middle: str = " " * (row_length - 2 - (spaces_length * 2)) # All rows, except the first and last, # have exactly two identical letters. result.append(spaces + char + middle + char + spaces) From 8f2c461701f6535b66d96ae6af485529f0772888 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 12 Oct 2025 12:35:16 -0700 Subject: [PATCH 3/3] Update diamond.py --- diamond/diamond.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diamond/diamond.py b/diamond/diamond.py index 747c256..ea9d514 100644 --- a/diamond/diamond.py +++ b/diamond/diamond.py @@ -15,7 +15,8 @@ def rows(letter: str) -> list[str]: Builds the upper half and mirrors it to form a symmetric diamond. - :param str letter: Uppercase letter (``'A'``-``'Z'``) marking the widest row. + :param str letter: Uppercase letter (``'A'``-``'Z'``) marking the + widest row. :returns: The full diamond as a list of strings, one per row. :rtype: list :raises ValueError: If ``letter`` is not an ASCII uppercase character.