-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest3.py
41 lines (33 loc) · 1 KB
/
test3.py
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
li=[]
with open("soundex_python.txt") as file:
data = file.read()
punc = '''-!()[]{};:'"\,<>./?@#$%^&*_~+=-'''
for element in data:
if element in punc:
data= data.replace(element, " ")
li=data.split()
def get_soundex(name):
name=name.upper()
soundex=""
soundex+=name[0]
dictionary = {"BFPV": "1", "CGJKQSXZ":"2", "DT":"3", "L":"4", "MN":"5", "R":"6", "AEIOUHWY":"."}
for char in name[1:]:
for key in dictionary.keys():
if char in key:
code = dictionary[key]
if code != soundex[-1]:
soundex += code
soundex = soundex.replace(".", "")
soundex = soundex[:4].ljust(4, "0")
return soundex
abc={}
lis=[]
if __name__ == '__main__':
for name in li:
abc[get_soundex(name)]=name
lis.append(get_soundex(name))
check=[]
for i in lis:
if lis.count(i) >1 and i not in check:
check.append(i)
print(f"{abc[i]} {i}")