You are given a set of square coordinates where we have placed white pawns. You should count how many pawns are safe.
def safe_pawns(pawns): pawns = [pawns[i:i + 2] for i in range(0, len(pawns), 2)] pawns = [chr(int(pawn[0]) + 97) + str(int(pawn[1]) - 1) for pawn in pawns] count = 0 for pawn in pawns: if chr(ord(pawn[0]) - 1) + str(int(pawn[1]) - 1) in pawns or chr(ord(pawn[0]) + 1) + str(int(pawn[1]) - 1) in pawns: count += 1 return count