-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththreeHomophones.py
More file actions
47 lines (38 loc) · 1 KB
/
threeHomophones.py
File metadata and controls
47 lines (38 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from pronounce import read_dictionary
prDict = read_dictionary()
prDict['oots'] = "OOTTSS"
prDict['twits'] = "TWitts"
#prDict['craws'] = "OOHED"
fin = open('words.txt')
letWords5 = {}
letWords4 = []
# put all 4 and 5 letter words in respective dictionaries
for line in fin:
word = line.strip()
if len(word) == 5:
letWords5[word] = []
elif len(word) == 4:
letWords4.append(word)
fin.close()
print len(letWords5)
count = 0
# at this point, letWords4 and letWords5 contains all 4 and 5 letter words, respectively
for word in letWords5:
if word not in prDict: continue
word2 = word[1:]
if word2 not in prDict: continue
word3 = word[0] + word[2:]
if word3 not in prDict: continue
pronounce1 = prDict[word]
pronounce2 = prDict[word2]
pronounce3 = prDict[word3]
if (pronounce1 == pronounce2) and (pronounce1 == pronounce3):
print "**** " + word
# string with first letter removed is string[1:]
# string with 2nd letter removed is string[0] + string[2:]
"""
**** llama
**** scent
**** llano
**** eerie
"""