代码拉取完成,页面将自动刷新
def soundex_al(word):
cap_word = word.upper() #convert the word to uppercase
return_val = ""
return_val = "" + cap_word[0] #get the first letter of the word
#dictonary to give values to the letters
code_dict = {"BFPV": "1", "CGJKQSXZ":"2", "DT":"3", "L":"4", "MN":"5", "R":"6"}
#array of charactors to remove from the word
rem_charactors = ["A","E","I","O","U","H","W","Y"]
#for loop to remove all the 0 valued charactors
temp = ""
for char in cap_word[1:]:
if char not in rem_charactors:
temp = temp + char
#get the values from the 'code_dict' and create the soundex code
for char in temp:
for key in code_dict.keys():
if char in key:
code = code_dict[key]
if code != return_val[-1]: #Remove all pairs of consecutive digits.
return_val += code
return_val = return_val[:4] #crop the word to 4 charactors
#if soundex code doen't contain 4 digits. fill it with zeros
if len(return_val) < 4:
for x in range(len(return_val), 4):
return_val = return_val + "0"
#return the value
return return_val
#testing the fucntion
print(soundex_al("Danus"))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。