gpt4 book ai didi

python - 这个错误: "TypeError: Parameters to generic types must be types"?是什么意思

转载 作者:行者123 更新时间:2023-12-01 00:23:30 29 4
gpt4 key购买 nike

我不确定这个错误意味着什么:

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

我试图确认矩阵中是否有给定的单元格/索引。(在矩阵[[A, B, C], [D, E, F]]中,单元格/索引[0, 2]存在吗?在C处是)。

我的输入参数是指定单元格索引的列表。我想获取单元格/列表并修改它以检查它是否存在。每次我尝试触摸参数列表时,都会出现错误。

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

最佳答案

这种类型 matr: List[List:int] 应该是 matr: List[List[int]] (在 Python >= 3.9 中,你甚至可以只使用 matr:列表[列表[int]])。

这意味着matr是一个整数列表的列表,例如:

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

关于python - 这个错误: "TypeError: Parameters to generic types must be types"?是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58791891/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com