Python script to generate words
I'm looking to write a short script that will allow me to generate all po开发者_开发技巧ssible letter combinations with the parameters I set.
For example:
__ _ _ n o
Parameters:
word = 5 letters
4th, 5th letter = n, o
1st letter = any vowel (aeiouy)
2nd, 3rd letter = any letter (abcde...)
in other words, I'm looking to write a script that would return me all 26*26*6 results. It does not matter if it is an actual word (i.e., "zzzno" is fine). And then to generalize it so I can do this with any parameters. Thank you.
import itertools
import string
letter = string.lowercase
vowel = "aeiouy"
def all_words(*args):
return (''.join(letters) for letters in itertools.product(*args))
wordlist = list(all_words(vowel, letter, letter, "n", "o"))
returns 4056 entries:
['aaano', 'aabno', 'aacno', 'aadno', 'aaeno', 'aafno' ... ]
If you have a word list, you don't even need to write code, you can use grep:
$ grep '^[aeiouy][a-z][a-z]no$' /usr/share/dict/words
amino
imino
精彩评论