<jupyter_start><jupyter_text>Valid SudokuDetermine if a 9x9 Sudoku board is valid.  Only the filled cells need to be validated according to the following rules:- Each row must contain the digits `1-9` without repetition- Each column must contain the digits `1-9` without repetitionn- Each of the 9 `3x3` sub-boxes of the grid must contain the digits `1-9`Note1. A Sudoku board (partial filled) could be valid but is not necessarily solveable.2. Only the filled cells need to be validated according to the rules Example 1```Input: board = [["5","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]]Output: true``` Example 2```Input: board = [["8","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]]Output: falseExplanation: Same as Example 1, except with the 5 in the top left corner being modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid.```  Notes```["8","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]```---- check the row for dups and check if not 1:9- check the column for dups and check if not 1:9- check the box for dups and check if not 1:9```check the rows def checkitems(board[0][:])     ["8","3",".",".","7",".",".",".","."]     [i for i in x if i != "."]     ["8", "3", "7"]     if len(list) != len(set(list):         return False```<jupyter_code>def hasDuplicates(items):
    return False if len(items) != len(set(items)) else True

def hasCorrectNumbers(items):
    for i, item in enumerate(items):
        if item < 1 or item > 9:
            return False
    return True

def removeBlank(items):
    return [i for i in items if i != "."]

def isValid(items):
    return not hasDuplicates(items) and hasCorrectNumbers(items)

def isValidSudoku(board):
    num_of_rows = len(board)
    
    for i in range(num_of_rows):
        row = removeBlank(board[i][:])
        column = removeBlank([j[i] for j in board])
        box = removeBlank(board)

        if not isValid(row) or not isValid(column) or not isValid(box):
            return False
        
    return True
        
        


print(isValidSudoku([
    ["8","3",".",".","7",".",".",".","."],
    ["6",".",".","1","9","5",".",".","."],
    [".","9","8",".",".",".",".","6","."],
    ["8",".",".",".","6",".",".",".","3"],
    ["4",".",".","8",".","3",".",".","1"],
    ["7",".",".",".","2",".",".",".","6"],
    [".","6",".",".",".",".","2","8","."],
    [".",".",".","4","1","9",".",".","5"],
    [".",".",".",".","8",".",".","7","9"]]))<jupyter_output>['8', '3', '7']
['6', '1', '9', '5']
['9', '8', '6']
['8', '6', '3']
['4', '8', '3', '1']
['7', '2', '6']
['6', '2', '8']
['4', '1', '9', '5']
['8', '7', '9']
None
{'fraction_non_alphanumeric': 0.4501580005745475, 'fraction_numerical': 0.05343292157426027, 'mean_word_length': 3.7895460797799174, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '610674', 'license': 'MIT', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1186, 'n_words': 284, 'path': 'EPIs/5-17_valid-sudoku.ipynb', 'repo_name': 'weklund/patterns-for-coding-questions', 'size': '3481'}