Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何检查子数组中是否有匹配的元素集_Python_Arrays_Optimization_Undefined_Sub Array - Fatal编程技术网

Python 如何检查子数组中是否有匹配的元素集

Python 如何检查子数组中是否有匹配的元素集,python,arrays,optimization,undefined,sub-array,Python,Arrays,Optimization,Undefined,Sub Array,我正在做一个tic-tac-toe应用程序,我想知道是否有一种方法可以创建一个函数来检查电路板并确定是否有人赢了? 我还想知道如何优化我的一些代码,因为,是的,我知道这是令人难以置信的草率。 另外,我使用Python3.9.5来实现这一点,没有其他语言 ''' ''' tic_tac_toe =[ [[0],[0],[0],[0]], [[0],[0],[0],[0]], [[0],[0],[0],[0]], [[0],[0],[0],[0]], ] pr

我正在做一个tic-tac-toe应用程序,我想知道是否有一种方法可以创建一个函数来检查电路板并确定是否有人赢了? 我还想知道如何优化我的一些代码,因为,是的,我知道这是令人难以置信的草率。 另外,我使用Python3.9.5来实现这一点,没有其他语言 '''

'''

tic_tac_toe =[
    [[0],[0],[0],[0]],
    [[0],[0],[0],[0]],
    [[0],[0],[0],[0]],
    [[0],[0],[0],[0]],
    ]
print(tic_tac_toe[1][1:4])
print(tic_tac_toe[2][1:4])
print(tic_tac_toe[3][1:4])
while True:
    print("where do you want to put X")
    while True:
        try:
            print("y-axis")
            input1 = int(input())
            print("x-axis")
            input2 = int(input())
            if "O" in tic_tac_toe[input1][input2]:
                print("there is already a varible there") 
            elif "X" in tic_tac_toe[input1][input2]:
                print("there is already a varible there")
            elif input1 == 0:
                print("out of range")
            elif input2 == 0:
                print("out of range")
            else:enter code here
                tic_tac_toe[input1][input2] = "X"
                print(tic_tac_toe[1][1:4])
                print(tic_tac_toe[2][1:4])
                print(tic_tac_toe[3][1:4])
                break
        except:
            print("out of range")
    print("where do you want to put O")
    while True:
        try:
            print("y-axis")
            input3 = int(input())
            print("x-axis")
            input4 = int(input())
            if "X" in tic_tac_toe[input3][input4]:
                    print("there is already a varible there") 
            elif "O" in tic_tac_toe[input3][input4]:
                print("there is already a varible there")
            elif input3 == 0:
                print("out of range")
            elif input4 == 0:
                print("out of range")
            else:
                tic_tac_toe[input3][input4] = "O"
                print(tic_tac_toe[1][1:4])
                print(tic_tac_toe[2][1:4])
                print(tic_tac_toe[3][1:4])
                break
        except:
            print("out of range")