summaryrefslogtreecommitdiffstats
path: root/func/yaml/ordered_dict.py
diff options
context:
space:
mode:
Diffstat (limited to 'func/yaml/ordered_dict.py')
-rw-r--r--func/yaml/ordered_dict.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/func/yaml/ordered_dict.py b/func/yaml/ordered_dict.py
new file mode 100644
index 0000000..5bc2e3e
--- /dev/null
+++ b/func/yaml/ordered_dict.py
@@ -0,0 +1,38 @@
+"""
+pyyaml legacy
+Copyright (c) 2001 Steve Howell and Friends; All Rights Reserved
+(see open source license information in docs/ directory)
+"""
+
+
+# This is extremely crude implementation of an OrderedDict.
+# If you know of a better implementation, please send it to
+# the author Steve Howell. You can find my email via
+# the YAML mailing list or wiki.
+
+class OrderedDict(dict):
+ def __init__(self):
+ self._keys = []
+
+ def __setitem__(self, key, val):
+ self._keys.append(key)
+ dict.__setitem__(self, key, val)
+
+ def keys(self):
+ return self._keys
+
+ def items(self):
+ return [(key, self[key]) for key in self._keys]
+
+if __name__ == '__main__':
+ data = OrderedDict()
+ data['z'] = 26
+ data['m'] = 13
+ data['a'] = 1
+ for key in data.keys():
+ print "The value for %s is %s" % (key, data[key])
+ print data
+
+
+
+