Hi All!

I am VERY NEW to Python and I am trying to make a program that can generate random words from a list of letters given to it. The command line can be:
program.py abcdefghi

and then as a result the program will print all possible 9 letter words.

Do you mean all combinations that are words or do you mean all combinations of the letters regardless if they form a correct word?

Do you mean all combinations that are words or do you mean all combinations of the letters regardless if they form a correct word?

All the words ..
As an improvement to this first program, we can search a list of valid words ( a small text file) to check the validity. If a generated word is in the file we will print it otherwise ignore it.

Your problem is called 'permutations'. If you have 9 unique letters, then you can get the 'factorial of 9' = 362880 number of permutations of 9 letter words.

To get words that are meaningful in a particuar language, you have to check against a dictionary of that langauge.

Your problem is called 'permutations'. If you have 9 unique letters, then you can get the 'factorial of 9' = 362880 number of permutations of 9 letter words.

To get words that are meaningful in a particuar language, you have to check against a dictionary of that langauge.

You are right but i dont know how to do that. Can you please give me some code examples!
Thank you very much!

Well, here is one example ...

``````# an example of string permutation

# needs Python26+
from itertools import permutations

mystr = 'abet'

perm_list = []
for perm in permutations(mystr):
perm_list.append(''.join(perm))

print( "Number of permutations = %s" % len(perm_list) )
for perm in perm_list:
print( perm )

print( '-'*12 )

# check against a list of words
word_list = ['best', 'bate', 'mate', 'abet', 'beat', 'beta', 'bat']
print("Words in word_list found:")
for perm in perm_list:
if perm in word_list:
print( perm )

"""my result-->
Number of permutations = 24
abet
abte
aebt
aetb
atbe
ateb
baet
bate
beat
beta
btae
btea
eabt
eatb
ebat
ebta
etab
etba
tabe
taeb
tbae
tbea
teab
teba
------------
Words in word_list found:
abet
bate
beat
beta
"""``````

Well, here is one example ...
`#` an example of string permutation

Thank you very much ... I will try to work on this!

Thank you again!