擅长:python、mysql、java
<p>使用OrderedDicts:<a href="http://docs.python.org/2/library/collections.html#collections.OrderedDict" rel="noreferrer">http://docs.python.org/2/library/collections.html#collections.OrderedDict</a></p>
<pre><code>>>> x = OrderedDict((("a", "1"), ("c", '3'), ("b", "2")))
>>> x["d"] = 4
>>> x.keys().index("d")
3
>>> x.keys().index("c")
1
</code></pre>
<p>对于那些使用Python 3的用户</p>
<pre><code>>>> list(x.keys()).index("c")
1
</code></pre>