【发布时间】:2019-08-19 18:36:13
【问题描述】:
我是 python 新手 我想在其中的集合模块中使用 defaultdict 编写代码,如下所示: 默认字典(lambda:'0') 但我只希望那些未定义键的值为 0,其中键大于 0,例如:我有这个 dict = {'24' : 3 ,'43' : 6} for dict['80'] 它应该为 0 但对于 dict['-5'] 应该为 1。有人可以帮忙
【问题讨论】:
-
如果你关心它们的数值,为什么键是字符串?
标签: python collections defaultdict