1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Python question

  1. Nov 8, 2005 #1
    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):
    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.
  2. jcsd
  3. Dec 1, 2005 #2
    string = "hio"
    for v in vowels:
    if v in string:
    string=string.replace(v," ")
    print string
  4. Dec 1, 2005 #3


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I'm not sure if you meant to say return or not, so I feel the need to point out that your function returns None, and not a string.

    P.S. is there any particular reason why you're testing if v is in string?
    Last edited: Dec 1, 2005
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Python question
  1. Python question (Replies: 1)

  2. Newbie python question (Replies: 4)

  3. Python 3 Question (Replies: 3)