写在此处,方便查阅

from collections import defaultdict

#需求: 需要创建一个字典容器,类似于 defaultdict(defaultdict(int))  的功能 ,在字典为空的情况下能够实现

# df['a']['b']+=1

def defaultdict_int():

    return defaultdict(int)

df=defaultdict(defaultdict_int)

df['a']['b']+=1

print df

根据 defaultdict 类的__init__方法,传入的工厂方法必须为可调用,所以,直接传入参数 defaultdict(int)  是会报错的

相关文章:

  • 2021-07-06
  • 2021-06-09
  • 2021-11-05
  • 2021-12-30
  • 2022-12-23
  • 2021-12-23
  • 2021-04-13
猜你喜欢
  • 2020-03-15
  • 2021-10-19
  • 2021-08-22
  • 2021-06-14
  • 2022-01-08
  • 2021-12-05
  • 2022-12-23
相关资源
相似解决方案