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


Python Dictionary.get_dict方法代码示例

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


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

示例1: Anagram

# 需要导入模块: from dictionary import Dictionary [as 别名]
# 或者: from dictionary.Dictionary import get_dict [as 别名]
class Anagram(object):
    
    def __init__(self):
        self.possible_words = set()
        self.output = set()
        self.dict = Dictionary()
        fich = open('Unabr.dict', 'r')
        self.dict.get_dict(fich)
        fich.close()
        
    def set_input(self, string):
        self.string = string
        
    def get_output(self):
        self.process('', list(self.string))
        for word in self.possible_words:
            if self.dict.is_in_dict(word):
                self.output.add(word)
        return self.output
    
    def process(self, string, l):
        if len(l) == 0:
            self.possible_words.add(string)
            return
        for index in range(len(l)):
            new_list = l[:]
            elem = new_list.pop(index)
            self.process(string + elem, new_list)            
开发者ID:antonioRubio,项目名称:anagram,代码行数:30,代码来源:anagram.py

示例2: Dictionary

# 需要导入模块: from dictionary import Dictionary [as 别名]
# 或者: from dictionary.Dictionary import get_dict [as 别名]
"""

FINISHED_TEMPLATE = u"""
<br/>
<pre>
        {message}

{definition}
</pre>
"""

# Load the dictionary
dictionary = Dictionary()

# Only use good words
valid_words = [k for k in dictionary.get_dict() if re.match('^[a-zA-Z]{4,20}$', k)]

class Hangman(object):
    def __init__(self):
        # Game variables
        self.state = 'NOT_PLAYING'
        self.word = None
        self.word_revealed = None
        self.guesses_right = None
        self.guesses_wrong = None

    def new_game(self):
        """
        Start a new game of hangman
        """
        if self.state == 'PLAYING':
开发者ID:Staberinde,项目名称:my-will,代码行数:33,代码来源:hangman.py


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