擅长:python、mysql、java
<p>这是因为<em>字典在Python中是无序的。如果希望保留键的顺序,则应尝试<code>OrderedDict</code>,如下所示。你知道吗</p>
<pre><code>from collections import OrderedDict
stb = OrderedDict(
TH0 = {0:'S0',1:'Sample1',2:'Sample2',3:'Sample4'},
TH1 = {0:'Sa0',1:'Sample1',2:'Sample2',3:'Sample4'},
TH2 = {0:'Sam0',1:'Sampled1.0',2:'Sampled2.0',3:'Sampled4.0'},
TH3 = {0:'Samp0',1:'Sample1',2:'Sample2',3:'Sample4'},
TH4 = {0:'Sampl0',1:'Sample1',2:'Sample2',3:'Sample4'},
)
tb = stb # As I see, this is not necessary (as we are not using std anywhere in the
# following code)
theaders = []
for k in tb.keys():
theaders.append(k)
columns = len(theaders)
rows = len(tb[theaders[0]])
print(tb[theaders[0]])
print('Cols: ',columns)
print('Rows: ',rows)
for h in theaders:
print(h)
</code></pre>