memo: dict[int, int] = {0: 0, 1: 1} # *our base cases*
返回以下错误:
TypeError: 'type' object is not subscriptable
我想您应该使用Dict
,例如:
from typing import Dict
memo: Dict[int, int] = {0: 0, 1: 1}
在您的情况下,您正在使用类型为dict
的type
>>> type(dict)
<class 'type'>
>>> type(Dict)
<class 'typing._GenericAlias'>
您可以执行以下操作:
from typing import Dict
mydict = Dict[int, int]
mydict = {0: 0, 1: 1}
结果:
>>>mydict
{0: 0, 1: 1}
如果这是您想要的。