Skip to content

Commit f12fa7f

Browse files
valentin-pBethanyG
authored andcommitted
concept string methods minor arrangement
1 parent aa9e69a commit f12fa7f

9 files changed

Lines changed: 42 additions & 36 deletions

File tree

concepts/str-methods/about.md

Whitespace-only changes.

concepts/str-methods/introduction.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

concepts/str-methods/links.json

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
Python provides a number of useful methods that you can use to manipulate
2-
strings. These methods can be used for cleaning, splitting, translating,
3-
or otherwise working with the str type. New strings can be created based
4-
on method arguments, and/or additional information can be returned. Strings
5-
can be concatenated using the `+` operator or with `str.join()`. Strings
6-
also implement all of the common sequence operations along with iteration using
7-
the `for item in <string>` syntax.
1+
Python provides several useful methods that can be used to manipulate strings.
2+
These methods can be used for cleaning, splitting, translating any variable of type `str`.
3+
Strings can be concatenated using the `+` operator or with `str.join()`.
4+
Strings also implement all of the common operations for a sequence and can be iterated using the syntax: `for item in <string>`.
85

9-
`Strings` are immutable (meaning the value does not change), so each of these
10-
methods will actually return a new instance of `str` instead of modifying
11-
the existing one.
6+
`Strings` are immutable, meaning their value in memory cannot change.
7+
It means the standard library methods will return a new instance of `str` instead of modifying the existing `str`.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
In this exercise you are helping your younger sister edit her paper for school. The teacher is looking for correct punctuation, grammar, and excellent word choice.
1+
In this exercise, you are helping your younger sister edit her paper for school. The teacher is looking for correct punctuation, grammar, and excellent choice of words.
22

33
You have four tasks to clean up and modify strings.
44

55
## 1. Capitalize the title of the paper
66

7-
Any good paper needs a properly formatted title. Implement the function `capitalize_title()` which takes in the parameter `title` and capitalizes the first letter of each word of the title. This function will return a `str`.
7+
Any good paper needs a properly formatted title. Implement the function `capitalize_title()` which takes `title` as parameter and capitalizes the first letter of each word of the title. This function will return a `str`.
88

99
```python
1010
>>> capitalize_title("my hobbies")
@@ -13,7 +13,7 @@ Any good paper needs a properly formatted title. Implement the function `capital
1313

1414
## 2. Check if each sentence ends with a period
1515

16-
You want to make sure that the punctuation in the paper is perfect. Implement the function `check_sentence_ending()` that takes in the parameter `sentence`. This function should return a `bool`.
16+
You want to make sure that the punctuation in the paper is perfect. Implement the function `check_sentence_ending()` that takes `sentence` as a parameter. This function should return a `bool`.
1717

1818
```python
1919
>>> check_sentence_ending("I like to hike, bake, and read.")
@@ -22,7 +22,7 @@ True
2222

2323
## 3. Clean up spacing
2424

25-
To make the paper look professional, unnecessary spacing needs to be removed. Implement the function `remove_extra_spaces()` which takes in the parameter `sentence` and removes extra whitespace at the beginning and at the end of the sentence. This function should return a `str`.
25+
For the paper to look professional, you need to remove unnecessary spacing. Implement the function `remove_extra_spaces()` which takes `sentence` as a parameter and removes any extra whitespace at the beginning and the end of the sentence. This function should return a `str`.
2626

2727
```python
2828
>>> remove_extra_spaces(" I like to go on hikes with my dog. ")
@@ -31,9 +31,9 @@ To make the paper look professional, unnecessary spacing needs to be removed. Im
3131

3232
## 4. Replace words with a synonym
3333

34-
To make the paper even better, you can replace some of the adjectives with synonyms. Write a function `replace_word_choice()` that takes in the parameters `sentence`, `old_word`, and `new_word`. This function should replace all instances of the `old_word` with the `new_word` and return the updated sentence. The function should return a `str`.
34+
To make the paper even better, you can replace some of the adjectives with synonyms. Write a function `replace_word_choice()` that takes `sentence`, `old_word`, and `new_word` as parameters. This function should replace all instances of the `old_word` with the `new_word` and return the updated sentence. The function should return a `str`.
3535

3636
```python
37-
>>> replace_word_choice("I bake good cakes", "good", "amazing")
38-
"I bake amazing cakes"
37+
>>> replace_word_choice("I bake good cakes.", "good", "amazing")
38+
"I bake amazing cakes."
3939
```
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
Python provides a number of useful methods that you can use to manipulate
2-
strings. These methods can be used for cleaning, splitting, translating,
3-
or otherwise working with the str type. New strings can be created based
4-
on method arguments, and/or additional information can be returned. Strings
5-
can be concatenated using the `+` operator or with `str.join()`. Strings
6-
also implement all of the common sequence operations along with iteration using
7-
the `for item in <string>` syntax.
1+
Python provides several useful methods that can be used to manipulate strings.
2+
These methods can be used for cleaning, splitting, translating any variable of type `str`.
3+
Strings can be concatenated using the `+` operator or with `str.join()`.
4+
Strings also implement all of the common operations for a sequence and can be iterated using the syntax: `for item in <string>`.
85

9-
`Strings` are immutable (meaning the value does not change), so each of these
10-
methods will actually return a new instance of `str` instead of modifying
11-
the existing one.
6+
`Strings` are immutable, meaning their value in memory cannot change.
7+
It means the standard library methods will return a new instance of `str` instead of modifying the existing `str`.

exercises/concept/little-sisters-essay/.meta/config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{
2+
"contributors": [
3+
{
4+
"github_username": "valentin-p",
5+
"exercism_username": "valentin-p"
6+
}
7+
],
28
"authors": [
39
{
410
"github_username": "kimolivia",

exercises/concept/little-sisters-essay/.meta/exemplar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ def check_sentence_ending(sentence):
55
return sentence.endswith(".")
66

77
def clean_up_spacing(sentence):
8-
new_sentence = sentence.strip()
9-
return new_sentence
8+
clean_sentence = sentence.strip()
9+
return clean_sentence
1010

1111
def replace_word_choice(sentence, new_word, old_word):
1212
better_sentence = sentence.replace(new_word, old_word)

exercises/concept/little-sisters-essay/string_methods_test.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,32 @@
22
from string_methods import *
33

44

5-
class test_string_methods(unittest.TestCase):
5+
class TestStringMethods(unittest.TestCase):
6+
def test_capitalize_word(self):
7+
self.assertEqual(capitalize_title("canopy"), "Canopy")
8+
69
def test_capitalize_title(self):
710
self.assertEqual(capitalize_title("fish are cold blooded"),
811
"Fish Are Cold Blooded")
912

1013
def test_sentence_ending(self):
1114
self.assertEqual(check_sentence_ending("Snails can sleep for 3 years."), True)
1215

16+
def test_sentence_ending_without_period(self):
17+
self.assertEqual(check_sentence_ending("Fittonia are nice"), False)
18+
19+
def remove_extra_spaces_only_start(self):
20+
self.assertEqual(remove_extra_spaces(" A rolling stone gathers no moss"),
21+
"A rolling stone gathers no moss")
22+
1323
def remove_extra_spaces(self):
1424
self.assertEqual(remove_extra_spaces(" Elephants can't jump. "),
1525
"Elephants can't jump.")
1626

1727
def test_replace_word_choice(self):
18-
self.assertEqual(replace_word_choice("Animals are cool", "cool", "awesome"),
19-
"Animals are awesome")
28+
self.assertEqual(replace_word_choice("Animals are cool.", "cool", "awesome"),
29+
"Animals are awesome.")
2030

2131
def test_replace_word_not_exist(self):
22-
self.assertEqual(replace_word_choice("Animals are cool", "small", "tiny"),
23-
"Animals are cool")
32+
self.assertEqual(replace_word_choice("Animals are cool.", "small", "tiny"),
33+
"Animals are cool.")

0 commit comments

Comments
 (0)