# -*- coding: utf-8 -*-<br /><br />import string
<em>def extend_word(text):<br /> if text.find('\'') > 0:<br /> old2new = dict()<br /> words = text.split()<br /> for word in words:<br /> if word.find('\'') > 0:<br /> parts = word.split('\'')<br /> if parts[1] == 'm':<br /> parts[1] = 'am'<br /> elif parts[1] == 's':<br /> parts[1] = 'is'<br /> elif parts[1] == 're':<br /> parts[1] = 'are'<br /> elif parts[1] == 't':<br /> parts[1] = 'not'<br /> elif parts[1] == 've':<br /> parts[1] = 'have'<br /> elif parts[1] == 'll':<br /> parts[1] = 'will'<br /> elif parts[1] == 'd':<br /> if words[words.index(word) +1] == 'better':<br /> parts[1] = 'had'<br /> else:<br /> parts[1] = 'would'<br /> if parts[0].endswith('n'):<br /> parts[0] =parts[0][:-1]<br /> old2new[word] = ' '.join(parts)<br /> _text = text<br /> for old_word in old2new.keys():<br /> _text = _text.replace(old_word, old2new[old_word])<br /> return _text<br /><br /><br />def show_in_order(record):<br /> items = sorted(records.items(), key=lambda item:item[1], reverse=True)<br /> for item in items:<br /> print(item[0], item[1])<br /><br />with open('1.txt', 'r') as file:<br /> article = file.read()<br /> no_pun_text = article<br /> _punctuation = string.punctuation.replace('\'', '')<br /> for pun in _punctuation:<br /> no_pun_text = no_pun_text.replace(pun, '')<br /> complete_text = extend_word(no_pun_text)<br /> records = dict()<br /> for word in complete_text.lower().split():<br /> records[word] = records.get(word, 0) + 1<br /> show_in_order(records)</em>