【发布时间】:2015-03-27 12:57:41
【问题描述】:
我的程序打开一个文件,它可以计算其中包含的单词,但我想创建一个包含文本中所有唯一单词的字典 例如,如果“计算机”一词出现 3 次,我希望将其计为一个唯一词
def main():
file = input('Enter the name of the input file: ')
infile = open(file, 'r')
file_contents = infile.read()
infile.close()
words = file_contents.split()
number_of_words = len(words)
print("There are", number_of_words, "words contained in this paragarph")
main()
【问题讨论】:
标签: python dictionary