99CHARS : str = string .ascii_uppercase
1010
1111
12- def rows (letter : str ) -> list :
12+ def rows (letter : str ) -> list [ str ] :
1313 """
1414 Return the diamond rows from 'A' to ``letter``.
1515
1616 Builds the upper half and mirrors it to form a symmetric diamond.
1717
18- :param str letter: Uppercase letter (``'A'``-``'Z'``) marking the widest row.
18+ :param str letter: Uppercase letter (``'A'``-``'Z'``) marking the
19+ widest row.
1920 :returns: The full diamond as a list of strings, one per row.
2021 :rtype: list
2122 :raises ValueError: If ``letter`` is not an ASCII uppercase character.
@@ -26,13 +27,15 @@ def rows(letter: str) -> list:
2627
2728 for i , char in enumerate (CHARS [: letter_index + 1 ]):
2829 # All rows have as many trailing spaces as leading spaces.
29- spaces : str = " " * (letter_index - i )
30+ spaces_length : int = letter_index - i
31+ spaces : str = " " * spaces_length
3032 # The first/last row contains one 'A'.
31- if i == 0 :
33+ if char == "A" :
3234 result .append (spaces + char + spaces )
3335 else :
34- middle : str = " " * (row_length - 2 - (len (spaces ) * 2 ))
35- # All rows, except the first and last, have exactly two identical letters.
36+ middle : str = " " * (row_length - 2 - (spaces_length * 2 ))
37+ # All rows, except the first and last,
38+ # have exactly two identical letters.
3639 result .append (spaces + char + middle + char + spaces )
3740 # Mirror the list: the bottom half has the letters in descending order.
3841 result = result + result [::- 1 ][1 :]
0 commit comments