词频统计

# 打开并读取文件
file = open(r'C:\Users\Administrator\Desktop\Walden.txt','r')
lines = file.readlines()
# 要把每行拆成单词
words = []

for line in lines:
    tmp_list = line.split()
    for word in tmp_list:
        words.append(word.replace(',','').replace('.','').replace('"','').replace(':',''))

words
['Walden',
 'Contents',
 'WALDEN',
 '1',
 'Economy',
 '2',
 'Where',
 'I',
 'Lived',
 'and',
 'What',
 'I',
 'Lived',
 'For',
 '3',
 'Reading',
 '4',
 'Sounds',
 '5',
 'Solitude',
 '6',
 'Visitors',
 '7',
 'The',
 'Bean-Field',
 '8',
 'The',
 'Village',
 '9',
 'The',
 'Ponds',
 '10',
 'Baker',
 'Farm',
 '11',
 'Higher',
 'Laws',
 '12',
 'Brute',
 'Neighbors',
 '13',
 'House-Warming',
 '14',
 'Inhabitants',
 'and',
 'Winter',
 'Visitors',
 '15',
 'Winter',
 'Animals',
 '16',
 'The',
 'Pond',
 'in',
 'Winter',
 '17',
 'Spring',
 '18',
 'Conclusion',
 '--',
 'On',
 'the',
 'Duty',
 'of',
 'Civil',
 'Disobedience',
 '--',
 'Economy',
 'When',
 'I',
 'wrote',
 'the',
 'following',
 'pages',
 'or',
 'rather',
 'the',
 'bulk',
 'of',
 'them',
 'I',
 'lived',
 'alone',
 'in',
 'the',
 'woods',
 'a',
 'mile',
 'from',
 'any',
 'neighbor',
 'in',
 'a',
 'house',
 'which',
 'I',
 'had',
 'built',
 'myself',
 'on',
 'the',
 'shore',
 'of',
 'Walden',
 'Pond',
 'in',
 'Concord',
 'Massachusetts',
 'and',
 'earned',
 'my',
 'living',
 'by',
 'the',
 'labor',
 'of',
 'my',
 'hands',
 'only',
 'I',
 'lived',
 'there',
 'two',
 'years',
 'and',
 'two',
 'months',
 'At',
 'present',
 'I',
 'am',
 'a',
 'sojourner',
 'in',
 'civilized',
 'life',
 'again',
 'I',
 'should',
 'not',
 'obtrude',
 'my',
 'affairs',
 'so',
 'much',
 'on',
 'the',
 'notice',
 'of',
 'my',
 'readers',
 'if',
 'very',
 'particular',
 'inquiries',
 'had',
 'not',
 'been',
 'made',
 'by',
 'my',
 'townsmen',
 'concerning',
 'my',
 'mode',
 'of',
 'life',
 'which',
 'some',
 'would',
 'call',
 'impertinent',
 'though',
 'they',
 'do',
 'not',
 'appear',
 'to',
 'me',
 'at',
 'all',
 'impertinent',
 'but',
 'considering',
 'the',
 'circumstances',
 'very',
 'natural',
 'and',
 'pertinent',
 'Some',
 'have',
 'asked',
 'what',
 'I',
 'got',
 'to',
 'eat;',
 'if',
 'I',
 'did',
 'not',
 'feel',
 'lonesome;',
 'if',
 'I',
 'was',
 'not',
 'afraid;',
 'and',
 'the',
 'like',
 'Others',
 'have',
 'been',
 'curious',
 'to',
 'learn',
 'what',
 'portion',
 'of',
 'my',
 'income',
 'I',
 'devoted',
 'to',
 'charitable',
 'purposes;',
 'and',
 'some',
 'who',
 'have',
 'large',
 'families',
 'how',
 'many',
 'poor',
 'children',
 'I',
 'maintained',
 'I',
 'will',
 'therefore',
 'ask',
 'those',
 'of',
 'my',
 'readers',
 'who',
 'feel',
 'no',
 'particular',
 'interest',
 'in',
 'me',
 'to',
 'pardon',
 'me',
 'if',
 'I',
 'undertake',
 'to',
 'answer',
 'some',
 'of',
 'these',
 'questions',
 'in',
 'this',
 'book',
 'In',
 'most',
 'books',
 'the',
 'I',
 'or',
 'first',
 'person',
 'is',
 'omitted;',
 'in',
 'this',
 'it',
 'will',
 'be',
 'retained;',
 'that',
 'in',
 'respect',
 'to',
 'egotism',
 'is',
 'the',
 'main',
 'difference',
 'We',
 'commonly',
 'do',
 'not',
 'remember',
 'that',
 'it',
 'is',
 'after',
 'all',
 'always',
 'the',
 'first',
 'person',
 'that',
 'is',
 'speaking',
 'I',
 'should',
 'not',
 'talk',
 'so',
 'much',
 'about',
 'myself',
 'if',
 'there',
 'were',
 'anybody',
 'else',
 'whom',
 'I',
 'knew',
 'as',
 'well',
 'Unfortunately',
 'I',
 'am',
 'confined',
 'to',
 'this',
 'theme',
 'by',
 'the',
 'narrowness',
 'of',
 'my',
 'experience',
 'Moreover',
 'I',
 'on',
 'my',
 'side',
 'require',
 'of',
 'every',
 'writer',
 'first',
 'or',
 'last',
 'a',
 'simple',
 'and',
 'sincere',
 'account',
 'of',
 'his',
 'own',
 'life',
 'and',
 'not',
 'merely',
 'what',
 'he',
 'has',
 'heard',
 'of',
 'other',
 "men's",
 'lives;',
 'some',
 'such',
 'account',
 'as',
 'he',
 'would',
 'send',
 'to',
 'his',
 'kindred',
 'from',
 'a',
 'distant',
 'land;',
 'for',
 'if',
 'he',
 'has',
 'lived',
 'sincerely',
 'it',
 'must',
 'have',
 'been',
 'in',
 'a',
 'distant',
 'land',
 'to',
 'me',
 'Perhaps',
 'these',
 'pages',
 'are',
 'more',
 'particularly',
 'addressed',
 'to',
 'poor',
 'students',
 'As',
 'for',
 'the',
 'rest',
 'of',
 'my',
 'readers',
 'they',
 'will',
 'accept',
 'such',
 'portions',
 'as',
 'apply',
 'to',
 'them',
 'I',
 'trust',
 'that',
 'none',
 'will',
 'stretch',
 'the',
 'seams',
 'in',
 'putting',
 'on',
 'the',
 'coat',
 'for',
 'it',
 'may',
 'do',
 'good',
 'service',
 'to',
 'him',
 'whom',
 'it',
 'fits',
 'I',
 'would',
 'fain',
 'say',
 'something',
 'not',
 'so',
 'much',
 'concerning',
 'the',
 'Chinese',
 'and',
 'Sandwich',
 'Islanders',
 'as',
 'you',
 'who',
 'read',
 'these',
 'pages',
 'who',
 'are',
 'said',
 'to',
 'live',
 'in',
 'New',
 'England;',
 'something',
 'about',
 'your',
 'condition',
 'especially',
 'your',
 'outward',
 'condition',
 'or',
 'circumstances',
 'in',
 'this',
 'world',
 'in',
 'this',
 'town',
 'what',
 'it',
 'is',
 'whether',
 'it',
 'is',
 'necessary',
 'that',
 'it',
 'be',
 'as',
 'bad',
 'as',
 'it',
 'is',
 'whether',
 'it',
 'cannot',
 'be',
 'improved',
 'as',
 'well',
 'as',
 'not',
 'I',
 'have',
 'travelled',
 'a',
 'good',
 'deal',
 'in',
 'Concord;',
 'and',
 'everywhere',
 'in',
 'shops',
 'and',
 'offices',
 'and',
 'fields',
 'the',
 'inhabitants',
 'have',
 'appeared',
 'to',
 'me',
 'to',
 'be',
 'doing',
 'penance',
 'in',
 'a',
 'thousand',
 'remarkable',
 'ways',
 'What',
 'I',
 'have',
 'heard',
 'of',
 'Bramins',
 'sitting',
 'exposed',
 'to',
 'four',
 'fires',
 'and',
 'looking',
 'in',
 'the',
 'face',
 'of',
 'the',
 'sun;',
 'or',
 'hanging',
 'suspended',
 'with',
 'their',
 'heads',
 'downward',
 'over',
 'flames;',
 'or',
 'looking',
 'at',
 'the',
 'heavens',
 'over',
 'their',
 'shoulders',
 'until',
 'it',
 'becomes',
 'impossible',
 'for',
 'them',
 'to',
 'resume',
 'their',
 'natural',
 'position',
 'while',
 'from',
 'the',
 'twist',
 'of',
 'the',
 'neck',
 'nothing',
 'but',
 'liquids',
 'can',
 'pass',
 'into',
 'the',
 'stomach;',
 'or',
 'dwelling',
 'chained',
 'for',
 'life',
 'at',
 'the',
 'foot',
 'of',
 'a',
 'tree;',
 'or',
 'measuring',
 'with',
 'their',
 'bodies',
 'like',
 'caterpillars',
 'the',
 'breadth',
 'of',
 'vast',
 'empires;',
 'or',
 'standing',
 'on',
 'one',
 'leg',
 'on',
 'the',
 'tops',
 'of',
 'pillars',
 '--',
 'even',
 'these',
 'forms',
 'of',
 'conscious',
 'penance',
 'are',
 'hardly',
 'more',
 'incredible',
 'and',
 'astonishing',
 'than',
 'the',
 'scenes',
 'which',
 'I',
 'daily',
 'witness',
 'The',
 'twelve',
 'labors',
 'of',
 'Hercules',
 'were',
 'trifling',
 'in',
 'comparison',
 'with',
 'those',
 'which',
 'my',
 'neighbors',
 'have',
 'undertaken;',
 'for',
 'they',
 'were',
 'only',
 'twelve',
 'and',
 'had',
 'an',
 'end;',
 'but',
 'I',
 'could',
 'never',
 'see',
 'that',
 'these',
 'men',
 'slew',
 'or',
 'captured',
 'any',
 'monster',
 'or',
 'finished',
 'any',
 'labor',
 'They',
 'have',
 'no',
 'friend',
 'Iolaus',
 'to',
 'burn',
 'with',
 'a',
 'hot',
 'iron',
 'the',
 'root',
 'of',
 'the',
 "hydra's",
 'head',
 'but',
 'as',
 'soon',
 'as',
 'one',
 'head',
 'is',
 'crushed',
 'two',
 'spring',
 'up',
 'I',
 'see',
 'young',
 'men',
 'my',
 'townsmen',
 'whose',
 'misfortune',
 'it',
 'is',
 'to',
 'have',
 'inherited',
 'farms',
 'houses',
 'barns',
 'cattle',
 'and',
 'farming',
 'tools;',
 'for',
 'these',
 'are',
 'more',
 'easily',
 'acquired',
 'than',
 'got',
 'rid',
 'of',
 'Better',
 'if',
 'they',
 'had',
 'been',
 'born',
 'in',
 'the',
 'open',
 'pasture',
 'and',
 'suckled',
 'by',
 'a',
 'wolf',
 'that',
 'they',
 'might',
 'have',
 'seen',
 'with',
 'clearer',
 'eyes',
 'what',
 'field',
 'they',
 'were',
 'called',
 'to',
 'labor',
 'in',
 'Who',
 'made',
 'them',
 'serfs',
 'of',
 'the',
 'soil?',
 'Why',
 'should',
 'they',
 'eat',
 'their',
 'sixty',
 'acres',
 'when',
 'man',
 'is',
 'condemned',
 'to',
 'eat',
 'only',
 'his',
 'peck',
 'of',
 'dirt?',
 'Why',
 'should',
 'they',
 'begin',
 'digging',
 'their',
 'graves',
 'as',
 'soon',
 'as',
 'they',
 'are',
 'born?',
 'They',
 'have',
 'got',
 'to',
 'live',
 'a',
 "man's",
 'life',
 'pushing',
 'all',
 'these',
 'things',
 'before',
 'them',
 'and',
 'get',
 'on',
 'as',
 'well',
 'as',
 'they',
 'can',
 'How',
 'many',
 'a',
 'poor',
 'immortal',
 'soul',
 'have',
 'I',
 'met',
 'well-nigh',
 'crushed',
 'and',
 'smothered',
 'under',
 'its',
 'load',
 'creeping',
 'down',
 'the',
 'road',
 'of',
 'life',
 'pushing',
 'before',
 'it',
 'a',
 'barn',
 'seventy-five',
 'feet',
 'by',
 'forty',
 'its',
 'Augean',
 'stables',
 'never',
 'cleansed',
 'and',
 'one',
 'hundred',
 'acres',
 'of',
 'land',
 'tillage',
 'mowing',
 'pasture',
 'and',
 'woodlot!',
 'The',
 'portionless',
 'who',
 'struggle',
 'with',
 'no',
 'such',
 'unnecessary',
 'inherited',
 'encumbrances',
 'find',
 'it',
 'labor',
 'enough',
 'to',
 'subdue',
 'and',
 'cultivate',
 'a',
 'few',
 'cubic',
 'feet',
 'of',
 'flesh',
 'But',
 'men',
 'labor',
 'under',
 'a',
 'mistake',
 'The',
 'better',
 'part',
 'of',
 'the',
 'man',
 'is',
 'soon',
 'plowed',
 'into',
 'the',
 'soil',
 'for',
 'compost',
 'By',
 'a',
 'seeming',
 'fate',
 'commonly',
 'called',
 'necessity',
 'they',
 'are',
 'employed',
 'as',
 'it',
 'says',
 'in',
 'an',
 'old',
 'book',
 'laying',
 'up',
 'treasures',
 'which',
 'moth',
 'and',
 'rust',
 'will',
 'corrupt',
 'and',
 'thieves',
 'break',
 'through',
 'and',
 'steal',
 'It',
 'is',
 'a',
 "fool's",
 'life',
 'as',
 'they',
 'will',
 'find',
 'when',
 'they',
 'get',
 'to',
 'the',
 'end',
 'of',
 'it',
 ...]
# 对words中每一个元素计算他出现的个数
#把统计结果保存到字典中,字典的key是单词,value是单词出现的次数
word_count = {}
word_set = set(words)
for word in word_set:
    count_num = word.count(word)
    word_count[word] = count_num
    
word_count    
{'': 1,
 'dirt': 1,
 'young': 1,
 'unbelievers': 1,
 'nerve': 1,
 'Neva': 1,
 'scorned': 1,
 'manifest': 1,
 'sundown': 1,
 'reverend': 1,
 'up': 1,
 'poet': 1,
 'up;': 1,
 'glorify': 1,
 'drudgery': 1,
 'cloths': 1,
 "e'er": 1,
 'persuaded': 1,
 'when': 1,
 'speeding': 1,
 'rail': 1,
 'trains': 1,
 'Through': 1,
 'occasioned': 1,
 'slice': 1,
 'completeness': 1,
 'prospecting': 1,
 'anon': 1,
 'poorly': 1,
 'furrowing': 1,
 'attaches': 1,
 'shirt': 1,
 '133': 1,
 'discussed': 1,
 'columns': 1,
 'River': 1,
 'maples': 1,
 'blow': 1,
 'think': 1,
 'solely': 1,
 'wool;': 1,
 'grenadiers': 1,
 'wooden': 1,
 'weathers': 1,
 'playing': 1,
 'landed': 1,
 'collect': 1,
 'dragon': 1,
 'cobweb': 1,
 'lunch': 1,
 'seldom': 1,
 'privileged': 1,
 'ate': 1,
 'Capacious': 1,
 'kindredship': 1,
 'light': 1,
 "mother-o'-pearl": 1,
 'now--': 1,
 'form': 1,
 'grievance': 1,
 'nation': 1,
 'devoting': 1,
 'comparable': 1,
 'knot': 1,
 'stray': 1,
 'fowling-piece': 1,
 'regularity;': 1,
 'men?': 1,
 'built;': 1,
 'manoeuvre': 1,
 'Walled-in': 1,
 'aunts': 1,
 'deem': 1,
 'revive': 1,
 'fluctuating': 1,
 'greatcoat': 1,
 'builders': 1,
 'revealed': 1,
 'since;': 1,
 'flapped': 1,
 'peculiarly': 1,
 'mid-day': 1,
 'Cast': 1,
 'squeamish;': 1,
 'resolved': 1,
 'ceasing': 1,
 'lazy': 1,
 'owns': 1,
 'occurred': 1,
 'paddle': 1,
 'close': 1,
 'co-operate': 1,
 'Russia': 1,
 'again': 1,
 'huts': 1,
 'dust': 1,
 'welcome': 1,
 'utensils': 1,
 "rabbit's": 1,
 'longer;': 1,
 'dwelt': 1,
 'ability': 1,
 'offers': 1,
 'pastures': 1,
 'reply': 1,
 'belies': 1,
 'sole': 1,
 'clout': 1,
 'breadthwise': 1,
 'sappy': 1,
 'Rans': 1,
 'thieves': 1,
 'prey': 1,
 'fail?': 1,
 'fare?': 1,
 'despaired': 1,
 'industriously': 1,
 '5th': 1,
 'clearing': 1,
 'costly': 1,
 'pressure': 1,
 'extreme': 1,
 'serenity!': 1,
 'battle;': 1,
 'Utopian': 1,
 'cost': 1,
 'dandelion': 1,
 'stress': 1,
 'shuffled': 1,
 'scrape': 1,
 'smeared': 1,
 'purpose?': 1,
 'things;': 1,
 'excuse': 1,
 'mysterious': 1,
 'inform': 1,
 'Fates': 1,
 'estimation': 1,
 'glen': 1,
 'pervade': 1,
 'unwieldy': 1,
 'yields': 1,
 'tendencies': 1,
 'face?': 1,
 'calling': 1,
 'princes': 1,
 'big': 1,
 'figures': 1,
 'coarsely': 1,
 'wonder': 1,
 'combine': 1,
 'thirty-two': 1,
 'touched': 1,
 'noticeable': 1,
 'admit': 1,
 'well-stocked': 1,
 'Enter': 1,
 'greatness': 1,
 'inquisitively': 1,
 'Vedas': 1,
 'improperly': 1,
 'attend': 1,
 'Are': 1,
 'despicable': 1,
 'leading': 1,
 'experiences;': 1,
 'sought': 1,
 'dense': 1,
 'separately': 1,
 'relief': 1,
 'kicks': 1,
 'declare': 1,
 'monster': 1,
 'vast': 1,
 'retracting': 1,
 'gun-stocks': 1,
 'cow-boy': 1,
 'tons': 1,
 'deeds': 1,
 'try': 1,
 'steam': 1,
 'unclean': 1,
 'rumor': 1,
 'cowhide': 1,
 'eagerly': 1,
 'permanently': 1,
 'casks': 1,
 'Elysian': 1,
 'May': 1,
 'axils': 1,
 'indifferently': 1,
 'dearth': 1,
 'attitude': 1,
 'vapor': 1,
 'stitch': 1,
 'flavor': 1,
 'mineral': 1,
 'account;': 1,
 'roofs': 1,
 'fish': 1,
 'without': 1,
 'raw;': 1,
 'mounts': 1,
 'ripened': 1,
 'palaver': 1,
 'simplifies': 1,
 'excluded': 1,
 'mower': 1,
 'enjoyed': 1,
 'Approving': 1,
 'visit': 1,
 'dwindled': 1,
 'oblations': 1,
 'abstract': 1,
 'Godspeed': 1,
 'slumbers': 1,
 'Wonder-Working': 1,
 'antiquaries': 1,
 'globus': 1,
 'prize': 1,
 'subdita': 1,
 'sturdiest': 1,
 'pulls': 1,
 'histories': 1,
 "sufferer's": 1,
 'Solomon': 1,
 'defiant': 1,
 'Supreme': 1,
 'natives': 1,
 'leaves;': 1,
 'presumption': 1,
 'pyramids': 1,
 'fact': 1,
 'head': 1,
 'River;': 1,
 'tracts': 1,
 'poor': 1,
 'kill': 1,
 'Phthia?': 1,
 'Cr': 1,
 'tents': 1,
 'well-tempered': 1,
 'feelings': 1,
 'clay': 1,
 'cutting': 1,
 'insects;': 1,
 'ruffled': 1,
 'delved': 1,
 'expanse': 1,
 'frequent': 1,
 'men;': 1,
 'today;': 1,
 'factitious': 1,
 'villages': 1,
 'swam': 1,
 'tainted': 1,
 'sake': 1,
 'longest': 1,
 'needy': 1,
 'ravines': 1,
 'valet': 1,
 'gray': 1,
 'perching': 1,
 'poll-tax': 1,
 'ranks': 1,
 'ova': 1,
 'stables': 1,
 'agriculture': 1,
 'smelted': 1,
 'forum': 1,
 'artery': 1,
 'half-hour': 1,
 'confesses': 1,
 'operated': 1,
 'friendliness': 1,
 'Consider': 1,
 'cunning': 1,
 'unquestionably': 1,
 'Hebe': 1,
 'moisture': 1,
 'humming': 1,
 'steel': 1,
 'bottle': 1,
 'giants': 1,
 'bench': 1,
 'honorable': 1,
 'bout': 1,
 'vegetables': 1,
 'spars': 1,
 'tossed': 1,
 'wiry': 1,
 'shines': 1,
 'conceptions': 1,
 'generous': 1,
 'usual': 1,
 'milked': 1,
 'fly': 1,
 'Throw': 1,
 'compel': 1,
 'queer': 1,
 'bather': 1,
 'fences;': 1,
 'rustling': 1,
 'telegraph': 1,
 'bestows': 1,
 'machinery': 1,
 'husbandman;': 1,
 'tinkering': 1,
 'tidbits': 1,
 'deriving': 1,
 'enough': 1,
 'sport': 1,
 'scented': 1,
 'genius;': 1,
 'loss': 1,
 'horizontally': 1,
 'sentimental': 1,
 'ship': 1,
 'Massachusetts': 1,
 'misery': 1,
 'well?': 1,
 'organizes': 1,
 'unreasonable': 1,
 'walking': 1,
 'employments': 1,
 'severed': 1,
 'substantial': 1,
 'reflection;': 1,
 'magnetism': 1,
 'done': 1,
 'above?': 1,
 'southern': 1,
 'situation': 1,
 'motes': 1,
 'indestructible': 1,
 '088': 1,
 'exempted': 1,
 'distorted': 1,
 'universe': 1,
 'bleak': 1,
 'assurance': 1,
 'sane': 1,
 'endangered': 1,
 'fates!': 1,
 'temperately': 1,
 'occupies': 1,
 'nerves': 1,
 '9': 1,
 '4': 1,
 'design': 1,
 'wilder': 1,
 'soon?': 1,
 'creatures': 1,
 'sled': 1,
 'great': 1,
 'levelled': 1,
 'widely': 1,
 'wood-nymph': 1,
 'regulating': 1,
 'seventy': 1,
 'suckers': 1,
 'direct': 1,
 'badge': 1,
 'precedents': 1,
 'Spring': 1,
 'plead': 1,
 'beneath;': 1,
 'differently': 1,
 'college': 1,
 'sills': 1,
 'pastoral': 1,
 'forsaken': 1,
 'sustains': 1,
 'swarm': 1,
 'excited;': 1,
 'do': 1,
 'broadest': 1,
 'rustle': 1,
 'attention': 1,
 'satellite': 1,
 'outer': 1,
 'reminds': 1,
 'shiners': 1,
 'purity?': 1,
 'springy': 1,
 'dyed': 1,
 'universally': 1,
 'lifetime': 1,
 'next': 1,
 'wealthy': 1,
 'wisest': 1,
 'precise': 1,
 'fruit;': 1,
 'smoothly': 1,
 'castle': 1,
 'practice': 1,
 'putty': 1,
 'crawling': 1,
 'fishermen;': 1,
 'worldly': 1,
 'impartially': 1,
 'quality': 1,
 'sermons': 1,
 'raisers': 1,
 'intellects': 1,
 'terms': 1,
 'favor': 1,
 'luxuriousness': 1,
 'republicans': 1,
 'tafferel': 1,
 'cantering': 1,
 'etiquette': 1,
 'where': 1,
 'transient': 1,
 'constellation': 1,
 'umbrellas': 1,
 'treasure': 1,
 'handed': 1,
 'here!': 1,
 'vitally': 1,
 'backgammon': 1,
 'rubbing': 1,
 'half-starved': 1,
 'directions': 1,
 'kitchen': 1,
 'wiseacre': 1,
 'Penn': 1,
 'driven': 1,
 'supply': 1,
 'sedes': 1,
 'lull': 1,
 'plaster': 1,
 'tinkling': 1,
 'Sundays': 1,
 'nearest': 1,
 'catechism': 1,
 'produces': 1,
 'revolutions': 1,
 'proceeding': 1,
 'Simplicity': 1,
 'tailor': 1,
 'here;': 1,
 '(Tetrao': 1,
 'professors': 1,
 'pickerelweed': 1,
 'northern': 1,
 'twittering': 1,
 'caraway': 1,
 'cookery': 1,
 'spared': 1,
 'prepared': 1,
 'Malays': 1,
 'winged': 1,
 'fisheries': 1,
 'leaping': 1,
 'extravagant': 1,
 'Then': 1,
 'issue': 1,
 'charmed': 1,
 'remote': 1,
 'remained;': 1,
 'Cut': 1,
 'suppliant': 1,
 'snipe;': 1,
 'mittens!': 1,
 'bullfrogs': 1,
 'Would': 1,
 'muggy': 1,
 'Given': 1,
 'Bright': 1,
 'rise': 1,
 'guard': 1,
 'cynosure': 1,
 'president': 1,
 'asks': 1,
 'spoon': 1,
 'ball': 1,
 'solitary?': 1,
 'cheeks': 1,
 'alligator': 1,
 'mortised': 1,
 'grossest': 1,
 'churchyard!': 1,
 'liquor;': 1,
 'locomotive': 1,
 'acquires': 1,
 'there': 1,
 'bigger': 1,
 'impaling': 1,
 'goldenrods': 1,
 'v': 1,
 'bluish-green': 1,
 'education': 1,
 'blessed': 1,
 'treat': 1,
 'rainiest': 1,
 'Davis': 1,
 'cups': 1,
 'everything': 1,
 'cats': 1,
 'maniac': 1,
 'slut': 1,
 'crippled': 1,
 'rainbow': 1,
 'laugh?': 1,
 'prevailing': 1,
 'rules': 1,
 'has': 1,
 'mouse': 1,
 'tread': 1,
 'habitually': 1,
 'shelf': 1,
 'framed': 1,
 'protracted': 1,
 "couldn't": 1,
 'Circling': 1,
 'woodenness': 1,
 'conduct': 1,
 'contemplate;': 1,
 'chanced': 1,
 'perturbation;': 1,
 'feather-edged': 1,
 'insanity': 1,
 'gray-headed': 1,
 'borrow': 1,
 'easy': 1,
 'large;': 1,
 'Visit': 1,
 'suggest': 1,
 'interior': 1,
 'umbrageous': 1,
 'whistle;': 1,
 'secretary': 1,
 'government;': 1,
 'suspected': 1,
 'cheaper': 1,
 'township': 1,
 'rendered': 1,
 'he;': 1,
 'substantials': 1,
 'importance': 1,
 'bayou': 1,
 'seventeen-year': 1,
 'looking-glass': 1,
 'Dutch': 1,
 'relic': 1,
 'Daily': 1,
 'addito': 1,
 'gained': 1,
 'enervates': 1,
 'tracks': 1,
 'Hoo': 1,
 'recess': 1,
 'slightly': 1,
 'Newfoundland': 1,
 'backs': 1,
 'Nec': 1,
 'tranquil': 1,
 'legislation?': 1,
 'wanderings': 1,
 'founding': 1,
 'than': 1,
 'spiring': 1,
 'Trojans': 1,
 'scornful': 1,
 'aerial': 1,
 'literature': 1,
 'earlier': 1,
 'fleet': 1,
 'fur': 1,
 'footpad': 1,
 'cells': 1,
 'friends': 1,
 'lay': 1,
 'diminished': 1,
 'them!': 1,
 'veins': 1,
 'synthetic': 1,
 'wave?': 1,
 'This': 1,
 'infants': 1,
 'continually': 1,
 'back?': 1,
 'incense': 1,
 'invisible': 1,
 'Myrmidons': 1,
 'associations': 1,
 'air': 1,
 'while': 1,
 'Is': 1,
 'sigh': 1,
 "Cato's": 1,
 'heaven!': 1,
 'skunk-cabbage': 1,
 'Tartarus': 1,
 'Middle': 1,
 'elicited': 1,
 'flags': 1,
 'inconvenience': 1,
 'confounded': 1,
 'fictile': 1,
 'approaching': 1,
 'hard': 1,
 'helve': 1,
 'dates': 1,
 'pursuit': 1,
 'vert': 1,
 'silent': 1,
 'wholesomer': 1,
 'worthy': 1,
 'repose': 1,
 'loudly': 1,
 'respectable;': 1,
 'whimsical': 1,
 'countrymen!': 1,
 'nature': 1,
 'teamster': 1,
 'tillage': 1,
 'Sky': 1,
 'kernels': 1,
 'won': 1,
 'Maine': 1,
 'napkin': 1,
 'sal-soda': 1,
 'contemplated': 1,
 'arose': 1,
 'clock;': 1,
 'roadside': 1,
 'giraffe;': 1,
 'Heroism': 1,
 'saloons': 1,
 'bearings': 1,
 'groceries': 1,
 'whispered': 1,
 'rest;': 1,
 'cut': 1,
 'auction': 1,
 'migrating': 1,
 'brazen': 1,
 'theory': 1,
 'marshes': 1,
 'saluted': 1,
 'motion': 1,
 'low-land': 1,
 'nymphs': 1,
 'entries': 1,
 'remoteness': 1,
 'offence': 1,
 'hammered': 1,
 'magnitude': 1,
 'dewy': 1,
 'quantities': 1,
 'Toss': 1,
 'Behold': 1,
 'molested': 1,
 'caravansary': 1,
 'outlet;': 1,
 'shire': 1,
 'laughs': 1,
 'Adam': 1,
 'prejudice': 1,
 'fight': 1,
 'met': 1,
 'indifference;': 1,
 'sighed': 1,
 'expressed': 1,
 'prescribed': 1,
 'Cinderella': 1,
 'stomach': 1,
 'noonday': 1,
 'new-rising': 1,
 'pursuers': 1,
 'intending': 1,
 'I': 1,
 'fragile': 1,
 'midst': 1,
 'folds': 1,
 'anew': 1,
 'interesting': 1,
 'substitutes': 1,
 'epochs': 1,
 'Austerlitz': 1,
 'limbed': 1,
 'valiant': 1,
 'She': 1,
 'Before': 1,
 'propertied': 1,
 '075': 1,
 'subsidence': 1,
 'Conclusion': 1,
 'consumed': 1,
 'designed': 1,
 'letter': 1,
 'month': 1,
 'Absolutely': 1,
 'tragedies': 1,
 'town-clerk': 1,
 'advantage;': 1,
 'counter': 1,
 'Turkey': 1,
 "countryman's": 1,
 'ordered': 1,
 'herb-doctor': 1,
 'lubeat': 1,
 'awning': 1,
 'games': 1,
 'nudgings': 1,
 'Potatoes': 1,
 'Fire!': 1,
 'instantaneously': 1,
 'indistinct': 1,
 'gay': 1,
 'grandeur': 1,
 'germ': 1,
 'opportunities': 1,
 'Woods;': 1,
 'colder': 1,
 'exist': 1,
 'Nails': 1,
 'footpath': 1,
 'piper-grass': 1,
 'trim': 1,
 'half-day': 1,
 'arrangement': 1,
 'Too': 1,
 'rabbit': 1,
 'waters': 1,
 'effectually': 1,
 'integrity': 1,
 'passage': 1,
 "another's": 1,
 'Scripture': 1,
 'cowards': 1,
 'piecemeal': 1,
 'miserable': 1,
 'dearly': 1,
 'intangible': 1,
 'disgust': 1,
 'Great': 1,
 'proving': 1,
 'entrance': 1,
 'railroad': 1,
 'pond;': 1,
 'polished': 1,
 'hurried': 1,
 'evils': 1,
 'took': 1,
 'comitatus': 1,
 'season': 1,
 'rice': 1,
 'fodder': 1,
 'An': 1,
 '$2812+': 1,
 'thickest': 1,
 'hand': 1,
 'partitions': 1,
 'jerk': 1,
 'commences': 1,
 'yours': 1,
 'Panem': 1,
 'alphabet': 1,
 'licks': 1,
 'utilitarian': 1,
 'Romance': 1,
 'herself': 1,
 'word': 1,
 'clinging': 1,
 'shores;': 1,
 'Blake': 1,
 'balanced': 1,
 'these': 1,
 'barrels': 1,
 'sting?': 1,
 'callow': 1,
 'quarrel': 1,
 'sermon': 1,
 'discharged': 1,
 'outlived': 1,
 'Clothing': 1,
 'blacksmith': 1,
 'Fridays': 1,
 'gird': 1,
 'hillsides': 1,
 'Gothic': 1,
 'redeemers': 1,
 'manner': 1,
 'motive': 1,
 'Norman': 1,
 'East': 1,
 'steady': 1,
 'sunk': 1,
 'exertion': 1,
 'next?': 1,
 'Poor': 1,
 "leopard's": 1,
 'matters': 1,
 'dollar': 1,
 "What's": 1,
 'canvas': 1,
 'dare': 1,
 'kitchens': 1,
 'builds': 1,
 '--': 1,
 'Czar': 1,
 'independently': 1,
 'ours': 1,
 'sloughs': 1,
 'else': 1,
 'ungainly': 1,
 'hall': 1,
 'correct': 1,
 'Angelo': 1,
 'Vaches': 1,
 'uncommonly': 1,
 'articles': 1,
 'careful': 1,
 'butt-end': 1,
 'until': 1,
 'Cheapest': 1,
 'venerable': 1,
 'moth': 1,
 'language': 1,
 'overshadowed': 1,
 'moment': 1,
 'peasant': 1,
 'disturber': 1,
 'blessing': 1,
 'Acheron': 1,
 'its': 1,
 'equivalent': 1,
 'Alas!': 1,
 'cleansed': 1,
 'cliffy': 1,
 'nap': 1,
 'genuine': 1,
 'smiles': 1,
 'fingers': 1,
 'freight': 1,
 'trailing': 1,
 'obtains': 1,
 'commenced': 1,
 'sliding': 1,
 'mischievous': 1,
 'Since': 1,
 'cronching': 1,
 'strive': 1,
 'exclusiveness': 1,
 'usefulness': 1,
 'speaking-trumpets': 1,
 'lobed': 1,
 'oceans;': 1,
 'truths': 1,
 'pretty': 1,
 'foliaceous': 1,
 'hobble': 1,
 'reasons': 1,
 'sweeping': 1,
 'Pleiades': 1,
 'cuckoos': 1,
 'blame': 1,
 'fogs': 1,
 'head;': 1,
 'gallery': 1,
 'decide': 1,
 'separate': 1,
 'pay': 1,
 'heard': 1,
 'Juno': 1,
 'mountainous': 1,
 'trivialness': 1,
 'horses!': 1,
 'mythology': 1,
 'ashamed': 1,
 'Flower': 1,
 'water-bugs': 1,
 'sculptors': 1,
 'resound': 1,
 'anticipated': 1,
 'mint': 1,
 'furring': 1,
 'the': 1,
 'appeared!': 1,
 'telescope': 1,
 'volatile': 1,
 'vulture': 1,
 'wade': 1,
 'Hill': 1,
 'burden': 1,
 'seizure': 1,
 'names': 1,
 'bolt': 1,
 'ripple': 1,
 'piles': 1,
 'inconveniency': 1,
 'seriousness': 1,
 'actual': 1,
 'uneven': 1,
 'development': 1,
 'tr-r-r--oonk': 1,
 'sparkles': 1,
 'neigh': 1,
 'angler': 1,
 'cure': 1,
 'Coleman': 1,
 'ought': 1,
 'bare': 1,
 'breath': 1,
 'worships': 1,
 'Finding': 1,
 'whinnering': 1,
 'impurity': 1,
 'studs': 1,
 'taint': 1,
 'Mountains;': 1,
 'Says': 1,
 'wormwood': 1,
 'resist': 1,
 'speaking': 1,
 'virtuous': 1,
 'machine': 1,
 'seaboard': 1,
 'crossing': 1,
 'aids': 1,
 'filled': 1,
 'outdoors': 1,
 'Books': 1,
 'library': 1,
 'assuage': 1,
 'whatever': 1,
 'vocation': 1,
 'splinter': 1,
 'foolish': 1,
 'panting': 1,
 'hard-working': 1,
 'lying': 1,
 'doubtless': 1,
 'discovers': 1,
 'smells': 1,
 'remnant': 1,
 'discovering': 1,
 'Pay': 1,
 'appear;': 1,
 'ludicrous': 1,
 'unfathomable': 1,
 'Lexington': 1,
 'microscope': 1,
 'cracking': 1,
 'heaved': 1,
 'aloof': 1,
 'propped': 1,
 'graceful': 1,
 'or': 1,
 'Venetian': 1,
 'fitting': 1,
 'row': 1,
 'Debate': 1,
 'watered': 1,
 'provincial?': 1,
 'seizing': 1,
 'depot': 1,
 'answer': 1,
 'buoys': 1,
 'opportunity': 1,
 'alarming': 1,
 'split': 1,
 'lisps': 1,
 'alert': 1,
 'tenoned': 1,
 'Still': 1,
 'manhood': 1,
 'tried;': 1,
 'blown': 1,
 'danger': 1,
 'robe;': 1,
 'threads': 1,
 'fleeting': 1,
 'know;': 1,
 'undefined': 1,
 'grand': 1,
 'towns': 1,
 'architecture!': 1,
 'prevailed': 1,
 'ambassador': 1,
 'presence': 1,
 'beginning': 1,
 "Hudson's": 1,
 '29th': 1,
 'urgent': 1,
 'dangled': 1,
 'rupture': 1,
 'Snows;': 1,
 'musical': 1,
 'clad': 1,
 'survived': 1,
 'nails': 1,
 'carts': 1,
 'additional': 1,
 'slop-shop': 1,
 'low': 1,
 'tavern': 1,
 ...}
# 对word_count字典进行排序,按照出现的次数(value)进行降序排序
# sorted(word_count.item.items(),key=lamba item: item:item[1])

# word_count.items()
# 整合代码输出文件
%%writefile 词频统计.py
# 打开并读取文件
file = open(r'C:\Users\Administrator\Desktop\Walden.txt','r')
lines = file.readlines()
# 要把每行拆成单词
words = []

for line in lines:
    tmp_list = line.split()
    for word in tmp_list:
        words.append(word.replace(',','').replace('.','').replace('"','').replace(':',''))

words
# 对words中每一个元素计算他出现的个数
#把统计结果保存到字典中,字典的key是单词,value是单词出现的次数
word_count = {}
word_set = set(words)
for word in word_set:
    count_num = word.count(word)
    word_count[word] = count_num
    
word_count    
# 对word_count字典进行排序,按照出现的次数(value)进行降序排序
# sorted(word_count.item.items(),key=lamba item: item:item[1])

# word_count.items()
# 整合代码输出文件
Writing 词频统计.py
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值