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.
Monday, September 28, 2009
Python - pig latin generator
Subscribe to:
Post Comments (Atom)
Cool. I used this in this script https://gist.github.com/1429538 that I want to put a BSD style license on. Is that okay? I don't see any copyright statement or licensing terms.
ReplyDelete@BT Feel free to use this script for whatever!
ReplyDelete