【发布时间】:2020-03-31 21:19:45
【问题描述】:
我有一个带有 2 个参数的函数。第一个是字符串,第二个是字典:
@functools.lru_cache(maxsize=None)
def flat_map(map_: Dict[str, List[str]], start: str) -> Dict[str, List[str]]:
if start not in map_:
return []
stars = map_[start] + [s for star in map_[start] for s in flat_map(star)]
return {star: stars for star in starmap}
运行这样的函数时:flat_map({'a': ['b', 'c'], 'b': ['c']}) 我收到以下错误:
TypeError: unhashable type: 'dict'
----> 1 flat_map({'a': ['b', 'c'], 'b': ['c']})
为什么会这样?如何解决?
【问题讨论】:
标签: python python-3.x caching typeerror mutability