Demo entry 6770293

字典key值排序

   

Submitted by anonymous on Nov 12, 2018 at 14:28
Language: Python 3. Code size: 128 Bytes.

D ={'a':1,'c':3,'b':2}
ks = list(D.keys())
ks.sort()
for key in ks:
    print(key, '=>',D[key])
#结果
a => 1
b => 2
c => 3

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).