Skip to content

Commit 97a6116

Browse files
Merge pull request #20 from madhukaraman/soundex
2 parents 8c64e3c + 169b850 commit 97a6116

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

soundex.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
##SOUNDEX ALGORITHM
2+
3+
text = 'AMANMADHUKAR' ##Enter your text here
4+
plain = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ## This is the plain text
5+
code = '01230120022455012623010202' ## Here I have assigned the code value respective to the alphabet
6+
l=[] ## Create empty list
7+
l.append(text[0]) ## So first character goes as it is (here it will be A)
8+
for i in range(1,len(text)): ## Traversing from 1st Index i.e. M to R over here that is the last character
9+
if(code[plain.index(text[i-1])]!=code[plain.index(text[i])]): ## Removing Zeroes from the list
10+
if (code[plain.index(text[i])] != '0'): ## If not zero
11+
l.append(code[plain.index(text[i])]) ## then append into list
12+
for i in range(4): ## Soundex considers only Four characters therefore traversing only four times
13+
if (len(l)<4): ## Suppose the Character less than four then we append 0 in last
14+
l.append('0')
15+
16+
17+
print(l) ##printing list
18+
print(''.join(l[:4])) ##lastly merging the list
19+
20+
21+
## Happy Coding :)

0 commit comments

Comments
 (0)