python - Sort dict alphabetically -
this question has answer here:
my program can output every student's name , 3 scores dict in file, need sort data alphabetical order. how can sort names , scores alphabetically according surname?
this code far: import pickle
def clssa(): filename="friendlist.data" f=open('class6a.txt','rb') storedlist = pickle.load(f) key, value in storedlist.items(): sorted (key), value in storedlist.items() print (("{} --> {}").format(key, value))
use sorted keyword.
for key, value in sorted(storedlist.items()): # etc
Comments
Post a Comment