[Python] operator.itemgetter
Word Counter Sorted by Times(Chinese Version):
import operator
in_file = open("input.txt")
raw_article = in_file.read()
table={}
for word in raw_article:
if word in table:
table[word] = table[word]+1
else:
table[word] = 1
sorted_table = sorted(table.items(),key=operator.itemgetter(1),reverse=True)
for pair in sorted_table:
print(pair[0],":",pair[1])