Showing posts with label vowel. Show all posts
Showing posts with label vowel. Show all posts

Monday, September 28, 2009

Python - pig latin generator

 
 
 
def makePigLatin(word):
    """ convert one word into pig latin """ 
    m  = len(word)
    vowels = "a", "e", "i", "o", "u", "y" 
    # short words are not converted 
    if m<3 or word=="the":
        return word
    else:
        for i in vowels:
            if word.find(i) < m and word.find(i) != -1:
                m = word.find(i)
        if m==0:
            return word+"way" 
        else:
            return word[m:]+word[:m]+"ay" 
 
 
sentence = "Hooray for pig latin" 
pigLatinSentence = "" 
# iterate through words in sentence 
for w in sentence.split(' '):
    pigLatinSentence += makePigLatin(w) + " " 
 
print pigLatinSentence.strip()
 
# output: 
# oorayHay orfay igpay atinlay 
 
 

Friday, July 10, 2009

Python remove vowels from a sentence

# create a tuple with vowels....yes I include y as a vowel
vowels = 'a', 'e', 'i', 'o', 'u', 'y'

# movie quote for our sentence
sentence = "My name is Werner Brandes, my voice is my password, verify me."


# iterate through the tuple of vowels
for vowel in vowels:
    # replace the vowel with nothing

    sentence = sentence.replace(vowel, '')

# display the vowel-less sentence!
print sentence

'M nm s Wrnr Brnds, m vc s m psswrd, vrf m.'


# additional string functions: http://docs.python.org/library/stdtypes.html

# manipulate vowels to create pig latin or double dutch