python - Outputting dictionary values by min/max value -
lets have dictionary:
dict1 = {'a': 3, 'b': 1.2, 'c': 1.6, 'd': 3.88, 'e': 0.72}
i need able sort min , max value , call on them using function still writing (note: 'occurences,' 'avg_scores' , 'std_dev' dictionaries , 'words' dictionary's keys.):
def sort(words, occurrences, avg_scores, std_dev): '''sorts , prints output''' menu = menu_validate("you must choose 1 of valid choices of 1, 2, 3, 4 \n sort options\n 1. sort avg ascending\n 2. sort avg descending\n 3. sort std deviation ascending\n 4. sort std deviation descending", 1, 4) print ("{}{}{}{}\n{}".format("word", "occurence", "avg. score", "std. dev.", "="*51)) if menu == 1: in range (len(word_list)): print ("{}{}{}{}".format(cnt_list.sorted[i],)
i'm sure making way more difficult on myself necessary , appreciated. thanks!
you can't sort dict, it's representation. but, can use ordereddict instead.
from collections import ordereddict dictionnary = ordereddict( sorted( {'a': 3, 'b': 1.2, 'c': 1.6, 'd': 3.88, 'e': 0.72 }.items(), key=lambda x:x[1], reverse=true))
Comments
Post a Comment