Skip to content

Commit c7ab848

Browse files
authored
Merge pull request #13 from ikostan/exercism-sync/ced40755b2f3e38d
[Sync Iteration] python/little-sisters-vocab/1
2 parents 3c3df58 + 2ba4223 commit c7ab848

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""Functions for creating, transforming, and adding prefixes to strings."""
2+
3+
4+
def add_prefix_un(word: str) -> str:
5+
"""
6+
Take the given word and add the 'un' prefix.
7+
8+
:param word: str - containing the root word.
9+
:return: str - of root word prepended with 'un'.
10+
"""
11+
return f'un{word}'
12+
13+
14+
def make_word_groups(vocab_words: list) -> str:
15+
"""
16+
Transform a list containing a prefix and words into a string with the prefix
17+
followed by the words with prefix prepended.
18+
19+
:param vocab_words: list - of vocabulary words with prefix in first index.
20+
:return: str - of prefix followed by vocabulary words with
21+
prefix applied.
22+
23+
This function takes a `vocab_words` list and returns a string
24+
with the prefix and the words with prefix applied, separated
25+
by ' :: '.
26+
27+
For example: list('en', 'close', 'joy', 'lighten'),
28+
produces the following string: 'en :: enclose :: enjoy :: enlighten'.
29+
"""
30+
return f' :: {vocab_words[0]}'.join(vocab_words)
31+
32+
33+
def remove_suffix_ness(word: str) -> str:
34+
"""
35+
Remove the suffix from the word while keeping spelling in mind.
36+
37+
:param word: str - of word to remove suffix from.
38+
:return: str - of word with suffix removed & spelling adjusted.
39+
40+
For example: "heaviness" becomes "heavy", but "sadness" becomes "sad".
41+
"""
42+
return f'{word[:-5]}y' if word[-5] == 'i' else word[:-4]
43+
44+
45+
def adjective_to_verb(sentence: str, index: int):
46+
"""
47+
Change the adjective within the sentence to a verb.
48+
49+
:param sentence: str - that uses the word in sentence.
50+
:param index: int - index of the word to remove and transform.
51+
:return: str - word that changes the extracted adjective to a verb.
52+
53+
For example, ("It got dark as the sun set.", 2) becomes "darken".
54+
"""
55+
words: list[str] = sentence.split()
56+
word: str = words[index].strip('.,!?')
57+
return f'{word}en'

0 commit comments

Comments
 (0)