Working on a homework question where all the vowels in a string need to be removed and if the letter \"g\" is beside a vowel, it would also be considered a vowel. For example gi
You can try using regex:
import re
def disemvowel(text): return re.sub(r"G?[AEIOU]+G?", "", text, flags=re.IGNORECASE) tests = {"fragrance": "frrnc", "gargden": "rgdn", "gargdenag": "rgdn", "gag": ""} for test, value in tests.items(): assert disemvowel(test) == value print("PASSED")
Output:
PASSED