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
A python example based blog that shows how to accomplish python goals and how to correct python errors.
Showing posts with label vowel. Show all posts
Showing posts with label vowel. Show all posts
Monday, September 28, 2009
Python - pig latin generator
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
Labels:
python,
remove,
replace,
string.replace,
vowel
Subscribe to:
Posts (Atom)