统计文章中的单词数量

#打开并读取文件
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.lower())
words
['\n',
 'walden\n',
 '\n',
 'contents\n',
 'walden\n',
 '1.',
 'economy\n',
 '2.',
 'where',
 'i',
 'lived,',
 'and',
 'what',
 'i',
 'lived',
 'for\n',
 '3.',
 'reading\n',
 '4.',
 'sounds\n',
 '5.',
 'solitude\n',
 '6.',
 'visitors\n',
 '7.',
 'the',
 'bean-field\n',
 '8.',
 'the',
 'village\n',
 '9.',
 'the',
 'ponds\n',
 '10.',
 'baker',
 'farm\n',
 '11.',
 'higher',
 'laws\n',
 '12.',
 'brute',
 'neighbors\n',
 '13.',
 'house-warming\n',
 '14.',
 'inhabitants',
 'and',
 'winter',
 'visitors\n',
 '15.',
 'winter',
 'animals\n',
 '16.',
 'the',
 'pond',
 'in',
 'winter\n',
 '17.',
 'spring\n',
 '18.',
 'conclusion\n',
 '--',
 'on',
 'the',
 'duty',
 'of',
 'civil',
 'disobedience',
 '--\n',
 'economy\n',
 '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.\n',
 '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.\n',
 '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',
 &#
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值