sort dictionary

mydict={"a":5,"b":1,"c":6};

sorted(mydict,key=mydict.get)
Out[58]: ['b', 'a', 'c']

sorted(mydict,key=mydict.get,reverse=True)
Out[59]: ['c', 'a', 'b']

usage of pickle

import cPickle;
x1=dict();
x2=dict();
x3=dict();
x1={1:"a",2:"b"};
x2={"a":1,"b":2};
x3={"f":1,"m":2};
cPickle.dump((x1,x2,x3),open("test.pkl","wb"));
p,q,r=cPickle.load(open("test.pkl","rb"));
print p;
print q;
print r;

05-11 13:17