import string import operator import collections # example data chars = {c: n for n, c in enumerate(string.ascii_uppercase)} sorted_chars = sorted(chars.items(), key=operator.itemgetter(1)) # chars.items() returns a list with tuples # each tuple is a key-value pair # the sorted function accepts a key function for sorting # operator.itemgetter(1) returns a function, which returns # the second element of a list # if you want to have a "sorted" dict, you should use OrderedDict from collections sorted_chars_dict = collections.OrderedDict(sorted_chars)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!