码迷,mamicode.com
首页 > 编程语言 > 详细

python的collections应用为字典哈希

时间:2018-11-09 17:43:10      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:append   python   list   key   def   pre   highlight   val   app   

import collections
allNum=collections.defaultdict(int)
allNum[1]+=1
allNum[5]+=1
print(allNum)

  当然,defaultdict里面的int,可以换为list,dict等等

换list则为:allNum[1].append(1)即:allNum[key].append(value)

python的collections应用为字典哈希

标签:append   python   list   key   def   pre   highlight   val   app   

原文地址:https://www.cnblogs.com/tangmiao/p/9936224.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!