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

Skip to content

Commit 8fa14d1

Browse files
committed
working
1 parent 3b12f6b commit 8fa14d1

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

15_kentucky_friar/friar.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,46 @@ def get_args():
3030
if os.path.isfile(args.text):
3131
lines = []
3232
for line in open(args.text):
33-
lines.append(line.strip())
33+
lines.append(line.rstrip())
3434

3535
args.text = '\n'.join(lines)
3636
return args
3737

3838
def fry(word):
39-
pattern1 = '([yY])(ou)([\W]*$)'
40-
m = re.match(pattern1, word)
41-
4239

40+
pattern1 = "([yY])(ou)([\W]["+string.ascii_letters+"]*)"
41+
m = re.match(pattern1, word)
4342

4443
if m:
4544
g = m.groups()
45+
# print(g)
46+
if g[2]:
47+
end = g[2]
48+
else:
49+
end=''
4650
if g[0] and g[1]:
47-
return f"{g[0]}'all"
51+
return f"{g[0]}'all"+end
52+
53+
pattern3 = "([yY])(ou)$"
54+
m = re.match(pattern3, word)
55+
if m:
56+
g = m.groups()
57+
return f"{g[0]}'all"
4858

4959
vowels = 'aeuoiAEUOI'
5060
consonants = ''.join(filter(lambda e: e not in vowels, string.ascii_letters))
51-
pattern2 = "(["+consonants+"]*)(["+vowels+"]+)[^'](["+consonants+"]*)(ing)(\W)?"
61+
pattern2 = "(["+string.ascii_letters+"]*)(ing)(\W)?"
5262

5363
m = re.match(pattern2, word)
5464
if m:
5565
g = m.groups()
56-
print(g)
57-
if g[4]:
58-
end = g[4]
66+
# print(g)
67+
if g[2]:
68+
end = g[2]
5969
else:
6070
end =''
61-
if g[1]:
62-
return ''.join(g[:3])+"in'" + end
71+
if len(list(filter(lambda e: e in vowels, g[0]))) > 0:
72+
return ''.join(g[0])+"in'" + end
6373

6474
return word
6575

@@ -77,7 +87,9 @@ def main():
7787
text = args.text
7888

7989
for line in args.text.splitlines():
80-
print(' '.join([fry(w) for w in line.split()]))
90+
# print(line)
91+
# print(re.split('\s', line))
92+
print(' '.join([fry(w) for w in re.split('\s', line)]))
8193

8294

8395

0 commit comments

Comments
 (0)