Skip to content

Instantly share code, notes, and snippets.

input_file = open('wordsEn.txt') #read the english word list from file
data = []
for line in input_file:
line = line.rstrip('\n') #ignore the '\n' in the file
line = line.rstrip('\r')
if len(line)>=5 and len(line)<=7:
#print line
data.append(line)
@icework
icework / anagram(hashmap).py
Created March 22, 2013 19:10
Anagram problem solve by hashmap
letterSortByFrequency = "etaoinsrhdlucmfywgpbvkxqjz"
primeNumber = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
letterToPrime = {}
for i in range(len(primeNumber)): # Create a map form letter to prime number, based on the frquency of each letter appear in english word
letterToPrime[letterSortByFrequency[i]] = primeNumber[i]
correctWord = {}
input_file = open('wordsEn.txt') #read the english word list from file
for line in input_file:
line = line.rstrip('\n') #ignore the '\n' in the file