は、重複を持つ単語の合計数をカウントしようとしていますが、これは{'count': 1, 'words.As': 1, 'said': 1, 'file.\n': 1, 'this': 1, 'text': 1, 'is': 1, 'of': 1, 'some': 1, ',i': 1, 'to': 1, 'only': 1, 'Hi': 1, 'a': 1, 'file': 1, 'recognize': 1, 'test': 1, 'the': 1, 'repeat': 1, 'before': 1}
カウント数 - 辞書内包表記を使用して、次のコードでのpython
になり、私は二回is
が表示されない、または任意私はここで間違って何をしているのですか?
test_readme.txt
Hi this is some text to recognize the count of words.As said before this is only a test file ,i repeat test file.
with open('test_readme.txt') as f:
di = { w : di[w]+1 if w in di else 1 for l in f for w in l.split(' ')}
print di
私は 'is'を2回見ます:'は単語の数を認識するためのテキストです。これは ' –
と言われています。あなたのコードから' TypeError:expected character buffer object'例外が発生します。 –