python - Sorting a list inside dictionary keys -
i have dictionary has student names key , list 3 scores test stored inside.
i need output keys in alphabetical order having list sorted in order high low.
any massively appreciated.
def task3(): import pprint classlist = {} classsearch = input("which class interrogate? ") try: open("answers " + classsearch + ".txt", 'rb') handle: classlist = pickle.loads(handle.read()) except ioerror error: print ("sorry, file not exist") sortoption = int(input("would sort students in alphabetical order? enter 1")) if sortoption == 1: #how sort list in order, guess have loop on dictionary able access keys pprint.pprint(classlist)
i think want achieve :
dictionary = {'louis': [2, 10, 1], 'john': [6, 1, 16] } name in sorted(dictionary.keys()): print name print sorted(dictionary[name], reverse=true)
the output :
john [16, 6, 1] louis [10, 2, 1]
Comments
Post a Comment