19

I'm not sure what this error means:

TypeError: Parameters to generic types must be types. Got slice(typing.List, <class 'int'>, None).

I am trying to confirm if a matrix has a given cell/index in it. (In matrix [[A, B, C], [D, E, F]] does cell/index [0, 2] exist? Yes at C).

My input parameter is a list specifying the cell's index. I want to take the cell/list and modify it to check if it exists. Every time I try to touch the parameter list, it gives the error.

def in_matrix(matr: List[List:int], cell: List[int]) -> bool:
    b = cell.pop()
    a = cell.pop()
    print(a)
    print(b)
    for y in range(len(matr)):
        for x in range(len(matr[y])):
            if matr[a][b] == True:
                return True
            else:
                return False

1 Answer 1

20

This type matr: List[List:int] should be matr: List[List[int]] (in Python >= 3.9 you can even just use matr: list[list[int]]).

This means that matr is a list of integer lists, like:

matr = [[1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]]
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.