Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def translate1(sentence):
- PIG_LATIN_RE = re.compile(
- r'''
- \b
- (
- [xy][^aeiou]\w*
- |
- [^aeiou\s]*
- (?: (?<=q)u )?
- )
- (\w*)
- \b
- ''', re.VERBOSE)
- return PIG_LATIN_RE.sub(r'\2\1ay', sentence)
- def substitute_word(match):
- if re.search(r'^[xy][^aeiou]', match.group(1)):
- return match.group(0) + "ay"
- else:
- return "{1}{0}ay".format(*match.groups())
- def translate2(sentence):
- PIG_LATIN_RE = re.compile(
- r'''
- \b
- (
- [^aeiou\s]*
- (?: (?<=q)u )?
- )
- (\w*)
- \b
- ''', re.VERBOSE)
- return PIG_LATIN_RE.sub(substitute_word, sentence)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement