Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate a list of all possible permutations of several letters? [duplicate]

So I am making a word generator that takes several inputted letters, puts them in all possible positions, and matches them with a document to find words. If I am approaching this wrong please tell me! If not how can I do this? Thanks

like image 306
codeman99 Avatar asked Dec 09 '22 10:12

codeman99


1 Answers

to generate all permutations of a given list of letters, use the itertools module.

import itertools 
for word in itertools.permutations( list_of_letters ):
   print ''.join(word)
like image 152
Colin Bernet Avatar answered Dec 28 '22 06:12

Colin Bernet