0

I'm trying to replace vowels/syllables in words with other text..for example:

Word entered: program

Text to replace syllables/vowels with: ab

Result: pr**ab**ogr**ab**am

AND if there is a wildcard (*) entered such as:

Word entered: dog

Text to replace syllables/vowels with: *b

Result: d**ob**og, where * is replaced with the the first vowel in the word, in this case being "o" and then it is replaced after that with the word entered, in this case "b" making "ob" put in before the vowel "o" in dog.

Any ideas? I am trying to accomplish this with for, if, and while loops only.

1
  • 4
    huh? I think you need to describe this algorithm a little better. Are you replacing syllables? vowels? What about words like tooth (1 syllable, 2 vowels)...And can you try to re-explain the second example? I'm not getting it. Commented Sep 22, 2012 at 3:27

1 Answer 1

1

You mean something like this?

re.sub(r'([aeoiu])', r'ab\1', 'program') -> 'prabograbam'

re.sub(r'([aeoiu])', r'\1b\1', 'dog') -> 'dobog'

or

re.sub(r'([aeoiu]+)', r'ab\1', 'tooth') -> 'tabooth'

re.sub(r'(([aeoiu])[aeoiu]*)', r'\2b\1', 'boat') -> 'boboat

Sign up to request clarification or add additional context in comments.

3 Comments

I'm trying to do this with for/if/while loops and not imported modules.
''.join([ 'ab'+x if x in 'aeiou' else x for x in 'program']) more pythonic than loops
That works, but can I substited 'ab' and 'program' for user inputted variables and it will work? I tried it and in shell it works, but when I try printing it comes out blank? For example, empty_str.join([first_syl+x if x in 'aeiou' else x for x in word]), then print (empty_str), it results in nothing in idle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.