为什么会出现错误?我已经正确添加了类型,对吗?
Invalid index type "str" for "Union[str, Dict[str, str]]"; expected type "Union[int, slice]"
代码
from typing import List, Dict, Union
d = {"1": 1, "2": 2}
listsOfDicts: List[Dict[str, Union[str, Dict[str, str]]]] = [
{"a": "1", "b": {"c": "1"}},
{"a": "2", "b": {"c": "2"}},
]
[d[i["b"]["c"]] for i in listsOfDicts]