$ python
>>> a = {}
>>> a["b"] = 1
>>> a["d"] = 2
>>> a["c"] = 3
>>> a["a"] = 4
>>> print a
{'a': 4, 'c': 3, 'b': 1, 'd': 2}
→ It's disjointed. ..
$ python
>>> a = []
>>> a.append(1)
>>> a.append(2)
>>> a.append(3)
>>> a.append(4)
>>> a.append(9)
>>> a.append(8)
>>> print a
[1, 2, 3, 4, 9, 8]
→ This seems OK.
$ python
>>> from collections import OrderedDict
>>> d = OrderedDict()
>>> d["b"] = 1
>>> d["d"] = 2
>>> d["c"] = 3
>>> d["a"] = 4
>>> print d
OrderedDict([('b', 1), ('d', 2), ('c', 3), ('a', 4)])
→ You can do it.
Where you don't really care about python? However, I had such a habit. Until sharing.
reference) http://docs.python.jp/2/tutorial/datastructures.html#tut-dictionaries
A dictionary is a set of unordered key: value pairs ...
Recommended Posts