Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7223554

Browse files
committed
make sure your is not changed
1 parent c018521 commit 7223554

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

15_kentucky_friar/solution1_regex.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ def main():
3838
def fry(word):
3939
"""Drop the `g` from `-ing` words, change `you` to `y'all`"""
4040

41-
if word.lower() == 'you':
42-
return word[0] + "'all"
41+
ing_word = re.search('(.+)ing$', word)
42+
you = re.match('([Yy])ou$', word)
4343

44-
if word.endswith('ing'):
45-
if any(map(lambda c: c.lower() in 'aeiouy', word[:-3])):
46-
return word[:-1] + "'"
47-
else:
48-
return word
44+
if ing_word:
45+
prefix = ing_word.group(1)
46+
if re.search('[aeiouy]', prefix, re.IGNORECASE):
47+
return prefix + "in'"
48+
elif you:
49+
return you.group(1) + "'all"
4950

5051
return word
5152

@@ -56,6 +57,7 @@ def test_fry():
5657

5758
assert fry('you') == "y'all"
5859
assert fry('You') == "Y'all"
60+
assert fry('your') == 'your'
5961
assert fry('fishing') == "fishin'"
6062
assert fry('Aching') == "Achin'"
6163
assert fry('swing') == "swing"

15_kentucky_friar/solution2_no_regex.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,12 @@ def main():
3838
def fry(word):
3939
"""Drop the `g` from `-ing` words, change `you` to `y'all`"""
4040

41-
ing_word = re.search('(.+)ing$', word)
42-
you = re.match('([Yy])ou$', word)
41+
if word.lower() == 'you':
42+
return word[0] + "'all"
4343

44-
if ing_word:
45-
prefix = ing_word.group(1)
46-
if re.search('[aeiouy]', prefix, re.IGNORECASE):
47-
return prefix + "in'"
48-
elif you:
49-
return you.group(1) + "'all"
44+
if word.endswith('ing'):
45+
if any(map(lambda c: c.lower() in 'aeiouy', word[:-3])):
46+
return word[:-1] + "'"
5047

5148
return word
5249

@@ -57,6 +54,7 @@ def test_fry():
5754

5855
assert fry('you') == "y'all"
5956
assert fry('You') == "Y'all"
57+
assert fry('your') == 'your'
6058
assert fry('fishing') == "fishin'"
6159
assert fry('Aching') == "Achin'"
6260
assert fry('swing') == "swing"

0 commit comments

Comments
 (0)