Smallest letter in a string As part of my college class, I have to write a program that returns the "smallest" letter in the string. Input is assumed to be a non empty string. "Smallest" is defined as:


  The smallest decimal value of the character, pertaining to this chart.


The range of acceptable values is 0 &lt;= x &lt;= 127

I would like to get feedback on the algorithm of the code. Other suggestions are accepted and welcome, but the main algorithm is the main focus.

def smallest_letter(string: str) -&gt; str:
    """
    Returns the smallest letter in the string

    Input is restricted to ASCII characters in range 0 &lt;= character &lt;= 127

    :param string: A string containing only ASCII letters

    :return: A string length one of the smallest letter
    """

    # Ensure all characters are within the acceptable range #
    for character in string:
        assert ord(character) &lt;= 127

    smallest_letter = 1000
    for letter in string:
        if ord(letter) &lt; smallest_letter:
            smallest_letter = ord(letter)
    return chr(smallest_letter)

if __name__ == "__main__":

    # Test Cases #

    assert smallest_letter("abydsufaksjdf") == "a"
    assert smallest_letter("bfsufsjfbeywafbiu") == "a"
    assert smallest_letter("ABYUVGDuibfsafuofiw") == "A"
Regarding min(string): Python exceeding your expectations. It happens a lot.

assert

All assert statements can be disabled with a switch to the interpreter, and sometimes are. Therefore, they're not suitable for flow control. I think you should replace:

for character in string:
    assert ord(character) &lt;= 127


With:

for character in string:
    if ord(character) &gt; 127:
        raise ValueError(f"Character {character} is out of range.")


or to optimize with a generator instead of the loop (requires Python 3.8+ if you want to report the character that violates the condition):

if any(ord(character := char) &gt; 127 for char in string):
    raise ValueError(f"Character {character} out of range")


(Thanks to @Graipher for proper handling of the := token in 3.8+, which I hadn't worked with myself yet.)

That's all I can see being wrong here, though.