【发布时间】:2020-08-07 17:52:48
【问题描述】:
我正在尝试转换以下列表:
listOfSets = [{"dog", "cat", "bird"}, {"blue", "yellow", "white"}]
到像这样的字典:
dictt = {"dog" : 0, "cat" : 0, "bird" : 0, "blue" : 1, "yellow" : 1, "white" : 1}}
我在这里尝试了其他帖子的建议,但没有成功, 例如,我尝试使用 enumerate 并得到以下错误:
Type error Unhashable type:set
当然要寻找最清晰和优雅的方式来实现它。
谢谢。
【问题讨论】:
标签: python list python-2.7 dictionary set