On Tue, Oct 7, 2008 at 5:58 PM, Emile van Sebille <[EMAIL PROTECTED]> wrote:
> Robert Berman wrote: > >> Hi, >> >> The below script which prints anagrams available for any word available >> within a given database. It does work, but it is not very fast. I am >> relatively certain there are more Python friendly coding techniques but I am >> more concerned with a faster algorithm. >> > > You might consider looking up the permutations only (up to some length -- > there are a lot of permutations for 8+ letter words :) > I'm not sure if this would be any faster, but I'd be curious at least to know what the difference would be to have a database of every possible permutation for every length up to 10, i.e: 0 01 10 012 021 102 120 201 210 . . . etc. And then simply use the key values of the letter... perhaps the anagrams stored in a dict by length as the key: mutations = {1: [(0,)], 2: [(0,1), (1,0)],} so for instance: myword = "if" mylen = len(myword) for mytuple in mutations[mylen]: for x in mytuple: print myword[x] I think that would work anyway. I don't know if I have the code right, and I'm not sure if it would be faster, slower, or no change, but it may be worth a look. HTH, Wayne -- To be considered stupid and to be told so is more painful than being called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, every vice, has found its defenders, its rhetoric, its ennoblement and exaltation, but stupidity hasn't. - Primo Levi
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor