#!/usr/bin/python
# This Python file uses the following encoding: utf-8
from __future__ import print_function
from operator import itemgetter


f1 = open('corpus.txt', 'r')
f2 = open('corpus2.txt', 'w')

for line in f1:
	temp = line.split()
	#print(temp[1])
	length = len(temp[1])
	f2.write(temp[0] + ' ' + temp[1] + ' ' + str(length) + '\n')

f1.close()
f2.close()

with open('corpus2.txt') as fin:
    lines = [line.split() for line in fin]
    freq = [line.split()[2] for line in fin]

#lines.sort(key=itemgetter(2), reverse = True)
lines.sort(key=lambda line: int(line[2]), reverse = True)
with open('corpus_len.txt', 'w') as fout:
    for el in lines:
        fout.write('{0}\n'.format(' '.join(el)))
