Is there a dictionary module in Python with ordering built-in? -
i know there ordereddict class want sort of mix between dict , priorityqueue.
so if iterate on dict, i'd items ordered value.
you can sort dictionary based on value so...
my_dict = {...} key in sorted(my_dict, key=lambda x: my_dict[x]): print (key + " " + my_dict[key])
keep in mind dictionary not sorted in place, sorted representation of dictionary.
also note can define basis on sort values via lambda function.
Comments
Post a Comment