I have a file that contains a list of words like:
word1 34
word2 12
word3 6
word4 498
word5 50
I want to sort the file by the numerical value. My code:
sortedfreqlist = sorted(freqlist, key=operator.itemgetter(1), reverse=True)
Doesn't quite work because it sorts the numbers as words i.e 12 comes before 6 etc.
Any ideas how I can do this?