#!python
# encoding: utf-8
import collections
def default_factory():
    return 'default value'

d=collections.defaultdict(default_factory,foo='bar',ok='ok')

print 'd:',d
print 'foo=>',d['foo']
print 'ok=>',d['ok']
print 'bar=>',d['bar']

黄聪:python中defaultdict标准字典的使用

 

相关文章:

  • 2021-07-21
  • 2022-12-23
  • 2021-11-21
  • 2021-11-14
  • 2022-12-23
  • 2021-06-22
  • 2021-06-28
  • 2021-07-05
猜你喜欢
  • 2021-07-30
  • 2022-12-23
  • 2023-04-07
  • 2021-09-18
  • 2022-12-23
  • 2021-12-11
  • 2022-12-23
相关资源
相似解决方案