我想从文本文件中获取每个单词,并在字典中计算单词频率.
例: 'this is the textfile, and it is used to take words and count'
d = {'this': 1, 'is': 2, 'the': 1, ...}
Run Code Online (Sandbox Code Playgroud)
我不是那么远,但我只是看不出如何完成它.我的代码到目前为止:
import sys
argv = sys.argv[1]
data = open(argv)
words = data.read()
data.close()
wordfreq = {}
for i in words:
#there should be a counter and somehow it must fill the dict.
Run Code Online (Sandbox Code Playgroud)