python 字典按照key 逆序

  1 #/usr/bin/env python
  2 from collections import OrderedDict
  3 print 'pyhton sort'
  4 mp={} 
  5 mp[1] =3;
  6 mp[3]=9;
  7 mp[2] = 2;
  8 mp=OrderedDict(sorted(mp.items(), key=lambda t: t[0],reverse = True))
  9 for (k,v) in mp.items() :
 10         print k,'-----',v

你可能感兴趣的:(python 字典按照key 逆序)