I have three numeric values (weight, count, contribution) for various strings (words) that i would like to organise into one multidimensional array, and then sort. To do this, I made lists within a dictionary, where the numeric values are in the list and the string is the key:
print_dictionary[word] = [weight,count,contribution]
How can I sort, first in ascending order and then in descending order, by 'contribution' (the third value in the list), and show the first 10 items of the sorted list. How can I do this?
For example, for the following print_dictionary:
print_dictionary[sam] = [2,7,1]
print_dictionary[sun] = [4,1,3]
print_dictionary[dog] = [1,3,2]
I want to them be able to sort contribution in ascending order:
Word: Weight: Count: Contribution:
sam 2 7 1
dog 1 3 2
sun 4 1 3
I don't see how itemegetter can be used for this:
sorted(print_dictionary, key=itemgetter(2))
print_dictionary.items().