I have a list, and it is currently sorted by key(A,B,C). The value is a number count of how many times the key appears in a file. The code gives results like this:
14 A
157 B
17 C
...
I need to reverse this order around. I want to sort by the value instead of key so it reads like this:
14 A
17 C
157 B
I have read and tried all the documentation I could find on here and Google. I don't think it should be too complex, but I am overthinking something.
Is there a simple solution to read the order by number value? Also every time I try to sort by value, it says 'int or str is not callable'. I don't understand what this means.
Some of my code is below:
lst = list()
for key, val in counts.items():
lst.append((key, val))
lst.sort()
for key, val in lst:
print val, key