[code.view]

[top] / python / PyMOTW / collections / collections_defaultdict.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2008 Doug Hellmann All rights reserved.
     #
     """Initializing a defaultdict.
     """
     
     __version__ = "$Id$"
     #end_pymotw_header
     
     import collections
     
     def default_factory():
         return 'default value'
     
     d = collections.defaultdict(default_factory, foo='bar')
     print 'd:', d
     print 'foo =>', d['foo']
     print 'bar =>', d['bar']
     

[top] / python / PyMOTW / collections / collections_defaultdict.py

contact | logmethods.com