Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def pig_latin(words):
- vwls = ['a','e','i','o','u']
- count = 0
- wlsts = words.split()
- final_list = []
- for n, word in enumerate(wlsts):
- wordlist = list(word) #forming a list out of string. strings are immutable but list are not
- new_word = []
- count = 1+ count
- if wordlist[0] in vwls:
- new_word = wordlist[1:]
- new_word.append(wordlist[0])
- else:
- new_word = wordlist
- new_word.append("ni")
- new_word.append('j'*count)
- new_word = ''.join(new_word) #forming the new word
- final_list.append(new_word)
- pig_latin = " ".join(final_list)
- return pig_latin
- #testing...
- sentence = "This is just an example"
- new_word = pig_latin(sentence)
- print (new_word)
- Thisnij sinijj justnijjj nanijjjj xampleenijjjjj
- ==========================================================
- #!/usr/bin/env python
- def pig_latin(sentence):
- vowels = 'aeiou'
- words = sentence.split()
- new_sentence = ''
- cntr = 1
- for word in words:
- if len(word) > 1 and word[0] in vowels:
- word = word[1:] + word[0]
- word += 'ni' + 'j'*cntr
- cntr += 1
- new_sentence += word + ' '
- return new_sentence.rstrip()
- if __name__ == '__main__':
- print pig_latin("This is just a small sentence")
- # Testing it:
- > python pig_latin.py
- Thisnij sinijj justnijjj anijjjj smallnijjjjj sentencenijjjjjj
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement