• + 0 comments

    Python can evaluate strings including numbers and letters

    >>> '0'<'1'<'2'<'3'<'4'<'5'<'6'<'7'<'8'<'9'<'X'
    True
    

    As you iterate through the grid the cavities are marked with the 'X' where all the adjacent cells are less than. For example

    1111
    1911
    1911
    1111
    

    returns with no cavities as 9 and 9 are equal.

    If we replace with an X it is because the surrounding cells evaluate as less than.

    So if 9 > 8 so too is X > 8 so the relationship between the cells is maintained and there is no need to check for X