Skip to content Skip to sidebar Skip to footer

How To Generate Word From A To Z

is it possible to create a method that generate a word from a to z ? cause i only know random generate word but what i want was a word that exist using python code this is the rand

Solution 1:

Do you mean something like? (untested):

from collections import defaultdict
from string import ascii_lowercase
from random import choice

words = defaultdict(list)
withopen('/usr/share/dict/words') as fin:
    for word in fin:
        iflen(word) == 5: 
            words.append(word)

for letter in ascii_lowercase:
    print letter, 'is for', choice(words[letter])

If you're not on a system that has /usr/share/dict/words (or you want a more comprehensive list), then http://www.findthatzip.com/search-10655738-hZIP/winrar-winzip-download-ukacd16.zip.htm is reasonably okay aswell.

Solution 2:

You'll likely need a list of words to choose from... once upon a time ago I needed one and I googled something like english dictionary txt... found a few and kept what looked the best to me

Then obviously you figure out how you're going to manage your list... infrequent use just read off the disk, maybe store the number of lines at the start of the file so you can select a number and read in only as far as you need... Or store them in memory for frequent use, an array probably

Post a Comment for "How To Generate Word From A To Z"