Every line of 'random word generator python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
34 def generate(ngram, seed): 35 """given an ngram dictionary and a string or tuple of words, this \ 36 returns a word. For efficiency, pass in all words as a list""" 37 if type(seed) is not tuple: 38 l = list() 39 tokens = utils.tokenize_normal_words(seed) 40 tokens = [t.lower() for t in tokens] 41 l.extend(tokens) 42 seed = tuple(l) 43 44 word = "" 45 if seed in ngram: 46 word = random.choice(ngram[seed]) 47 # print "found in dictionary" 48 # print ngram[seed] 49 50 # elif words is None: 51 # print "Combining all dictionary values." 52 # words = sum(ngram.values(), []) 53 # word = random.choice(words) 54 # else: 55 # word = random.choice(words) 56 return word
32 def random_word(language="eng"): 33 w = choice(list(data.etyms[language])) 34 return Word(w, language)
412 def _generate_ngram_word(word_list_gen): 413 ''' 414 415 :param word_list_gen: 一个字符串的迭代器 416 :return: 417 ''' 418 word_list = [] 419 for w in word_list_gen: 420 word_list.append(w) 421 n = len(word_list) 422 ans = [] 423 for i in range(1, n+1): 424 for j in range(0, n+1-i): 425 ans.append(''.join(word_list[j:j+1])) 426 return ans
26 def randomword(length): 27 letters = string.ascii_lowercase 28 return ''.join(random.choice(letters) for i in range(length))
63 def pickWord(self): 64 '''Returns a word as string from the wordlist.''' 65 66 while True: 67 word = choice(self.wordlist).rstrip() 68 try: 69 return word.encode("ascii", "ignore") 70 except: 71 pass