- #1
Erik Horwath
- 7
- 0
I need to write a function that takes an input string and returns it minus all vowels and another that returns it with each vowel duplicated. ie - in the first case, removeVowels("Zippy") would return "Zppy" and in the second case duplicateVowels("Zippy") would return "Ziippy". I know it is something obvious, but it won't come to me. I have been trying things along the line of:
def removeVowels(string):
vowels="AaEeIiOoUu"
for v in vowels:
if v in string:
newstring=string.replace(v," ")
print newstring
But i need some way to modify the statement newstring=string.replace(v," ") such that for each iteration in the for loop the dot replace method operates on the newstring from the previous iteration, not the original string. That is, in the current format removeVowels("lightbulb") returns "lightblb" not "lghtblb" Thanks.
def removeVowels(string):
vowels="AaEeIiOoUu"
for v in vowels:
if v in string:
newstring=string.replace(v," ")
print newstring
But i need some way to modify the statement newstring=string.replace(v," ") such that for each iteration in the for loop the dot replace method operates on the newstring from the previous iteration, not the original string. That is, in the current format removeVowels("lightbulb") returns "lightblb" not "lghtblb" Thanks.