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
Generic types have one or more type parameters, which can be arbitrary types. For example, dict[int, str] has the type parameters int and str , and list[int] has a type parameter int .
A generic type is a generic class or interface that is parameterized over types. The following Box class will be modified to demonstrate the concept.
The generic argument list is a comma-separated list of type arguments. A type argument is the name of an actual concrete type that replaces a corresponding type parameter in the generic parameter clause of a generic type. The result is a specialized version of that generic type.
Generic MethodsA type parameter, also known as a type variable, is an identifier that specifies a generic type name. The type parameters can be used to declare the return type and act as placeholders for the types of the arguments passed to the generic method, which are known as actual type arguments.
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]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With