[code.view]

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

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2010 Doug Hellmann.  All rights reserved.
     #
     """Iterating over an OrderedDict
     """
     #end_pymotw_header
     
     import collections
     
     print 'Regular dictionary:'
     d = {}
     d['a'] = 'A'
     d['b'] = 'B'
     d['c'] = 'C'
     d['d'] = 'D'
     d['e'] = 'E'
     
     for k, v in d.items():
         print k, v
     
     print '\nOrderedDict:'
     d = collections.OrderedDict()
     d['a'] = 'A'
     d['b'] = 'B'
     d['c'] = 'C'
     d['d'] = 'D'
     d['e'] = 'E'
     
     for k, v in d.items():
         print k, v
         
     

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

contact | logmethods.com