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!

Homework Help: 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
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Similar Threads for Python question Date
Python 3 Question Sep 23, 2014
Quick Question about Python concatenation Jan 13, 2014
Database Python Question Jun 4, 2013
Monte Carlo Python Plotting Question May 23, 2013
Python/orbital question Apr 17, 2013