我正在使用Python 3.11。strs 的 dicts 的 dict 的类型提示将如下所示:
dict[dict[str, str]]
Run Code Online (Sandbox Code Playgroud)
但是如果我想为未知深度的字典提供提示怎么办?
例如,我想编写一个函数,它从元组列表(父级,后代)以字典形式构造树:
source = [('a', 'b'), ('b', 'c'), ('d', 'e')]
target = {'a': {'b': {'c': {}}}, 'd': {'e': {}}}
def tree_form(source: list[tuple[str, str]]) -> ???:
"""code"""
pass
Run Code Online (Sandbox Code Playgroud)
我应该写什么而不是“???”?