Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def validWord(word: str) -> bool:
- valid_char = ['a', 'e', 'i', 'o', 'u', 'p', 'k', 'h', 'l', 'm', 'n', 'w', '\'', ' ']
- for char in word:
- if char not in valid_char:
- return False
- return True
- def pronunciate(phrase: str) -> str:
- singleLetter = {'a': 'ah', 'e': 'eh', 'i': 'ee', 'o': 'oh', 'u': 'oo'}
- doubleLetter = {'ai': 'eye', 'ae': 'eye', 'ao': 'ow', 'au': 'ow', 'ei': 'ay',
- 'eu': 'eh - oo', 'iu': 'ew', 'oi': 'oy',
- 'ou': 'ow', 'ui': 'ooey'}
- pronunciation = ''
- counter = 0
- phrase = phrase.lower()
- for i in range(len(phrase)):
- if counter == 0:
- if phrase[i:i + 2] in doubleLetter:
- pronunciation += doubleLetter[phrase[i:i + 2]]
- counter += 1
- if (i < len(phrase) - 2) and (phrase[i + 1] not in (' ', '\'')):
- pronunciation += '-'
- elif phrase[i] in singleLetter:
- pronunciation += singleLetter[phrase[i]]
- if (i < len(phrase) - 1) and (phrase[i + 1] not in (' ', '\'')):
- pronunciation += '-'
- else:
- pronunciation += phrase[i]
- else:
- counter = 0
- if 'w' in pronunciation:
- dissection = []
- for char in pronunciation:
- dissection.append(char)
- for i in range(len(dissection)):
- if dissection[i] == 'w':
- if dissection[i - 1] in ('\'', ' ', '-'):
- if dissection[i - 2] in ('i', 'e'):
- dissection[i] = 'v'
- elif dissection[i - 2] in ('u', 'o'):
- dissection[i] = 'v'
- else:
- if dissection[i - 1] in ('i', 'e'):
- dissection[i] = 'v'
- elif dissection[i - 1] in ('u', 'o'):
- dissection[i] = 'v'
- pronunciation = ''.join(dissection)
- str_list = pronunciation.split(' ')
- final = ''
- for str in str_list:
- final += str.capitalize()
- final += ' '
- return final
- print(pronunciate('E komo mai'))
- print(pronunciate('hoaloha'))
- print(pronunciate('humuhumunukunukuapua\'a'))
- print(pronunciate('Mahalo wahine'))
- print(pronunciate('maika\'i mahalo'))
- print(pronunciate('iwa'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement