You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Little Sister's Vocab]: Fixed up Code Examples for str.join() & Added an Additional Hint. (#3995)
* Fixed up code examples for join and added an additional hint.
* Touched up hints phrasing, added no loop directive to instructions, and added additional examples to concept about.
* Typo correction.
* Corrected separator misspelling.
* Cleaned up in-line comments per PR review.
* Fixed capitalization on inline comments in last join example.
Copy file name to clipboardExpand all lines: concepts/strings/about.md
+34-4Lines changed: 34 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ The Python docs also provide a very detailed [unicode HOWTO][unicode how-to] tha
9
9
Strings implement all [common sequence operations][common sequence operations] and can be iterated through using `for item in <str>` or `for index, item in enumerate(<str>)` syntax.
10
10
Individual code points (_strings of length 1_) can be referenced by `0-based index` number from the left, or `-1-based index` number from the right.
11
11
12
-
Strings can be concatenated with `+`, or via `<str>.join(<iterable>)`, split via `<str>.split(<separator>)`, and offer multiple formattingand assembly options.
12
+
Strings can be concatenated with `+`, or via `<str>.join(<iterable>)`, split via `<str>.split(<separator>)`, and offer multiple formatting, assembly, and templating options.
13
13
14
14
15
15
A `str` literal can be declared via single `'` or double `"` quotes. The escape `\` character is available as needed.
@@ -168,12 +168,12 @@ sentence = word + " " + "means" + " " + number + " in " + language + "."
168
168
"дев'ять means nine in Ukrainian."
169
169
```
170
170
171
-
If a `list`, `tuple`, `set` or other collection of individual strings needs to be combined into a single `str`, [`<str>.join(<iterable>)`][str-join], is a better option:
171
+
If a `list`, `tuple`, `set` or other collection of individual strings needs to be combined into a single `str`, [`<str>.join(<iterable>)`][str-join] is a better option:
172
172
173
173
174
174
```python
175
175
# str.join() makes a new string from the iterables elements.
176
-
>>> chickens = ["hen", "egg", "rooster"]
176
+
>>> chickens = ["hen", "egg", "rooster"]# Lists are iterable.
177
177
>>>''.join(chickens)
178
178
'hen egg rooster'
179
179
@@ -183,6 +183,34 @@ If a `list`, `tuple`, `set` or other collection of individual strings needs to b
183
183
184
184
>>>' 🌿 '.join(chickens)
185
185
'hen 🌿 egg 🌿 rooster'
186
+
187
+
188
+
# Any iterable can be used as input.
189
+
>>> flowers = ("rose", "daisy", "carnation") # Tuples are iterable.
190
+
>>>'*-*'.join(flowers)
191
+
'rose*-*daisy*-*carnation'
192
+
193
+
>>> flowers = {"rose", "daisy", "carnation"} # Sets are iterable, but output order is not guaranteed.
194
+
>>>'*-*'.join(flowers)
195
+
'rose*-*carnation*-*daisy'
196
+
197
+
>>> phrase ="This is my string"# Strings are iterable, but be careful!
Copy file name to clipboardExpand all lines: exercises/concept/little-sisters-vocab/.docs/hints.md
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,8 +14,11 @@ There's four activities in the assignment, each with a set of text or words to w
14
14
15
15
## 2. Add prefixes to word groups
16
16
17
-
- Believe it or not, [`str.join()`][str-join] is all you need here.
18
-
- Like [`str.split()`][str-split]`, `str.join()` can take an arbitrary-length string, made up of any unicode code points.
17
+
- Believe it or not, [`str.join()`][str-join] is all you need here. **A loop is not required**.
18
+
- The tests will be feeding your function a `list`. There will be no need to alter this `list` if you can figure out a good delimiter string.
19
+
- Remember that delimiter strings go between elements and "glue" them together into a single string. Delimiters are inserted _without_ space, although you can include space characters within them.
20
+
- Like [`str.split()`][str-split], `str.join()` can process an arbitrary-length string, made up of any unicode code points. _Unlike_`str.split()`, it can also process arbitrary-length iterables like `list`, `tuple`, and `set`.
0 commit comments