Created
July 18, 2011 07:59
-
-
Save basarat/1088833 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#the wordlist file is the SCOWL wordlist downloaded from : http://wordlist.sourceforge.net/ | |
file = open("./SCOWL/wordlist.txt") | |
words =[line[:-1] for line in file.readlines()] #remove the newline character. | |
file.close() | |
#basic anagram comparion algorithm | |
def AreSameCharacters(word1,word2): | |
word1 = list(word1) | |
word2 = list(word2) | |
word1.sort() | |
word2.sort() | |
word1 = "".join(word1).lower() | |
word2 = "".join(word2).lower() | |
return word1==word2 | |
def IsAnagramEqual(word1,word2): | |
if (word1==word2): | |
return False #we do not list the same word as an anagram :) | |
if len(word1) != len(word2): | |
return False | |
if not AreSameCharacters(word1,word2): | |
return False | |
return True | |
#word input by user | |
word1 = str(raw_input("Please Input Your Word: ")).strip().lower() | |
#single word comparisons: | |
for word2 in words: | |
if IsAnagramEqual(word1,word2): | |
print word2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment