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

Skip to content

Commit 17c7a81

Browse files
committed
my solution
1 parent dade9a0 commit 17c7a81

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

14_rhymer/rhymer.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ def main():
4949

5050
pattern = '(['+consonants()+']+)?(.*)?'
5151

52-
groups = re.match(pattern, text).groups()
52+
groups = re.match(pattern, text.lower()).groups()
5353

54-
if groups[0] and groups[1]:
55-
printRhymeWords(groups[1])
54+
if groups[1]:
55+
printRhymeWords(groups[0], groups[1])
5656
else:
5757
first=groups[0] or ''
58-
print(f'Cannot rhyme "{first}{groups[1]}"')
58+
print(f'Cannot rhyme "{args.word}"')
5959

6060

61-
def printRhymeWords(rest):
61+
def printRhymeWords(leading_consonants, rest):
6262

6363
replacements="""
6464
bl br ch cl cr dr fl fr gl gr pl pr sc sh sk sl sm sn sp st
@@ -67,7 +67,13 @@ def printRhymeWords(rest):
6767

6868
replacements.extend(list(consonants()))
6969

70-
[print(c) for c in list(map(lambda w: print(w+rest), replacements)).sort()]
70+
sorted_list = sorted(replacements)
71+
72+
r = [c for c in sorted_list if c != leading_consonants]
73+
for x in r:
74+
print(x+rest)
75+
# sorted(map(print, replacements))
76+
# [print(c) for c in list(map(lambda w: print(w+rest), replacements)).sort()]
7177

7278
# --------------------------------------------------
7379
if __name__ == '__main__':

0 commit comments

Comments
 (0)