当前位置: 首页>>代码示例>>Python>>正文


Python Dictionary.search_words方法代码示例

本文整理汇总了Python中dictionary.Dictionary.search_words方法的典型用法代码示例。如果您正苦于以下问题:Python Dictionary.search_words方法的具体用法?Python Dictionary.search_words怎么用?Python Dictionary.search_words使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dictionary.Dictionary的用法示例。


在下文中一共展示了Dictionary.search_words方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from dictionary import Dictionary [as 别名]
# 或者: from dictionary.Dictionary import search_words [as 别名]
class Wordplay:
    def __init__(self):
        self.dico = Dictionary()

    def __del__(self):
        self.dico.close()


    def open(self, dictionary_path):
        self.dico.open(dictionary_path)


    def close(self):
        self.dico.close()


    def search_words(self, pattern):
        for word in self.dico.search_words(pattern):
            yield word


    def letters_for_three_words(self, word1_begin, word2_begin, word3_begin, word_end_len):
        word1_suffixes = set(self._search_suffixes(word1_begin, word_end_len))
        word2_suffixes = set(self._search_suffixes(word2_begin, word_end_len))
        word3_suffixes = set(self._search_suffixes(word3_begin, word_end_len))

        common_suffixes = word1_suffixes & word2_suffixes & word3_suffixes
        for common_suffix in sorted(common_suffixes):
            yield common_suffix


    def quatro(self, prefix1, suffix1, prefix2, suffix2, middleLength):
        word1_middle = set(self._search_middle(prefix1, suffix1, middleLength))
        word2_middle = set(self._search_middle(prefix2, suffix2, middleLength))

        common_middles = word1_middle & word2_middle
        for common_middle in sorted(common_middles):
            yield common_middle


    def _search_middle(self, prefix, suffix, middleLength):
        for word in self.dico.search_words(prefix + "_" * middleLength + suffix):
            middle = word[len(prefix):-len(suffix)]

            yield middle


    def _search_suffixes(self, word_begin, word_end_len):
        for word in self.dico.search_words(word_begin + "_" * word_end_len):
            suffix = word[-word_end_len:]

            yield suffix

    def search_anagrams(self, word):
        for anagram in self.dico.search_anagrams(word):
            yield anagram
开发者ID:killruana,项目名称:wordplay,代码行数:58,代码来源:wordplay.py


注:本文中的dictionary.Dictionary.search_words方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。