for wclass in word_class_dict[most_ambigious_word]:
for sent in brown_sents:
if (most_ambigious_word.capitalize(), wclass) in sent or (most_ambigious_word.upper(), wclass) in sent or (most_ambigious_word.lower(), wclass) in sent:
print most_ambigious_word,"-",wclass
print " ".join(tuple[0] for tuple in sent)
break
为了澄清brown_sents
是一个元组列表,不能更改。至于简化的部分,我发现这3个不同的检查有点难写。有什么想法吗?在
编辑(对于那些对分配任务感兴趣的人): brown-sents是元组的列表,其中包含以下元素:
^{pr2}$所以,我在找say word1
,但情况应该不重要。一、 例如,word1
与{wclass
是wordclass,所以我只想打印出包含不同的word1,wclass
对的句子(显然,如果word1有多个wordclass,我想遍历wordclass并打印出所有单词的一个示例,这是最外层的for循环)。在
这其实就是所需要的。在
这应该是有效的:
如果搜索多个单词,则创建一个集合是有意义的:
Example
^{pr2}$输出
要理解它的作用,请将脚本保存到一个文件中,例如
search-word.py
,然后运行:它显示Python提示符:
您可以尝试单个表达式来查看它们的作用,例如:
查看帮助:
按
q
退出。如果个别帮助信息不清晰:请尝试查看模块的联机帮助:
找到^{} 函数。在
简而言之:阅读文档,在提示下尝试一些代码,重复。如果你卡住了,ask question。在
相关问题 更多 >
编程相关推荐