Skip to content

Instantly share code, notes, and snippets.

@2get
Created December 5, 2012 08:34
Show Gist options
  • Save 2get/4213849 to your computer and use it in GitHub Desktop.
Save 2get/4213849 to your computer and use it in GitHub Desktop.
Python OrderedDict
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from collections import OrderedDict
print '### Standard Dict ###'
d = {}
for i in range(1, 11):
d['key%03d' % i] = 'value%03d' % i
for key, value in d.items():
print key, value
print '### OrderedDict ###'
d = OrderedDict()
for i in range(1, 11):
d['key%03d' % i] = 'value%03d' % i
for key, value in d.items():
print key, value
'''
### Standard Dict ###
key001 value001
key003 value003
key002 value002
key005 value005
key004 value004
key007 value007
key006 value006
key009 value009
key008 value008
key010 value010
### OrderedDict ###
key001 value001
key002 value002
key003 value003
key004 value004
key005 value005
key006 value006
key007 value007
key008 value008
key009 value009
key010 value010
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment