Python - Anagram Maker





2
Date Submitted Mon. Jun. 9th, 2008 4:06 AM
Revision 1 of 1
Helper jamesmcm
Tags anagram | python
Comments 0 comments
A simple anagram maker written in python. Automatically adds original word to wordlist.txt if it does not exist there already so it may be used in conjunction with the solver.

#Anagram Maker
import random
import array

wordlist=open("wordlist.txt","a")
readit=open("wordlist.txt","r")
iread=readit.read()
word=raw_input("Please enter word to be anagramized: ")
word = word.lower()
pword = word + "\n"

#Add new word to word list if it does not already exist
#NOTE: Only use this for real words - else will create false positives

if iread.find("\n" + pword) == -1:
    wordlist.write(pword)
   
wordlist.close()

word=word.replace("\n", "")
newword = array.array('c')
newword.fromstring(word)
randused = []
i=0
#print len(word)
while i < len(word):
    randnum=random.randrange(0, len(word))
    if randnum not in randused:
        randused.append(randnum)
        #oldchar=word[i]
        newword[i]=word[randnum]
        i+=1
        #newword[randnum]=oldchar

print newword.tostring()
 

james mcm

Comments

There are currently no comments for this snippet.

Voting

Votes Up


Syntax Master dannyboy
Helper jamesmcm

Votes Down