问题描述
说我已经在python中定义了一个不可变的类型,但是我想创建该类型的可变版本。具体来说,我的用例是从MutableMapping
中获取Mapping
。
我的例子:
from typing import List,Mapping
IntsByStr = Mapping[str,List[str]]
def build_map(input_strings: List[List[str]]) -> IntsByStr:
# How do I create this type from IntsByStr? Without repeating myself by doing:
# MutableIntsByStr = MutableMapping[str,List[str]]
my_map: MutableIntsByStr = {}
for [str1,*strs] in input_strings:
my_map[str1] = [str1,*strs]
return my_map
这些不是我正在使用的实际类型或确切代码,我知道我本可以使用字典理解的,但是出于示例的目的。我的实际情况更复杂,字典理解也不适合。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)