朱丽叶和朱丽叶的剧本我有多少次要从《罗密欧》的剧本中找到。在
以下是文本:http://pastebin.com/X0gaxAPK
文中有三个人在发言:格雷戈里、桑普森和亚伯拉罕。在
基本上我想做3个不同的字典(如果这是最好的方法吗?)三位演讲者中的每一位。用人们各自说的单词填充字典,然后计算他们在整个脚本中说每个单词的次数。在
我该怎么做呢?我想我能算出字数,但我有点困惑,不知道如何区分谁说了什么,并把它编入每个人的3个不同的词典。在
我的输出应该如下所示(这不是正确的,而是一个示例):
Gregory -
25: the
15: a
5: from
3: while
1: hello
etc
其中数字是文件中所说单词的频率。在
现在我写了一些代码来读取文本文件,去掉标点符号,并将文本编译成一个列表。我也不想使用任何外部模块,我想用老式的方式来学习,谢谢。在
你不必发布确切的代码,只要解释一下我需要做什么,希望我能弄明白。我用的是python3。在
下面是一个简单的实现:
输出示例:
^{pr2}$你不想马上去掉标点符号。一个新行前面的冒号告诉你一个人的引语开始和结束的位置。这一点很重要,这样你就可以知道在哪本词典中要将引用的单词追加到哪个词典中。你可能会需要一些if-else,它会根据当前说话的人而附加到不同的字典中。在
相关问题 更多 >
编程相关推荐