Skip to content

Commit a4df5d4

Browse files
committed
Fixed up code examples for join and added an additional hint.
1 parent ab7852e commit a4df5d4

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

exercises/concept/little-sisters-vocab/.docs/hints.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ There's four activities in the assignment, each with a set of text or words to w
1616

1717
- Believe it or not, [`str.join()`][str-join] is all you need here.
1818
- Like [`str.split()`][str-split]`, `str.join()` can take an arbitrary-length string, made up of any unicode code points.
19+
- The tests will be feeding your function a `list`. There will be no need to alter this list, provided you use `.join()` correctly.
1920

2021
## 3. Remove a suffix from a word
2122

exercises/concept/little-sisters-vocab/.docs/introduction.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ If a `list`, `tuple`, `set` or other collection of individual strings needs to b
5050

5151
```python
5252
# str.join() makes a new string from the iterables elements.
53-
>>> chickens = ["hen", "egg", "rooster"]
53+
>>> chickens = ["hen", "egg", "rooster"] #lists are iterable
5454
>>> ' '.join(chickens)
5555
'hen egg rooster'
5656

@@ -60,8 +60,37 @@ If a `list`, `tuple`, `set` or other collection of individual strings needs to b
6060

6161
>>> ' 🌿 '.join(chickens)
6262
'hen 🌿 egg 🌿 rooster'
63+
64+
65+
# Any iterable can be used as input.
66+
>>> flowers = ("rose", "daisy", "carnation") #tuples are iterable
67+
>>> '*-*'.join(flowers)
68+
'rose*-*daisy*-*carnation'
69+
70+
>>> flowers = {"rose", "daisy", "carnation"} #sets are iterable, but output order is not guaranteed.
71+
>>> '*-*'.join(flowers)
72+
'rose*-*carnation*-*daisy'
73+
74+
>>> phrase = "This is my string" #strings are iterable, but be careful!
75+
>>> '..'.join(phrase)
76+
'T..h..i..s.. ..i..s.. ..m..y.. ..s..t..r..i..n..g'
77+
78+
79+
# Separators are inserted **between** elements, but can be any string (including spaces).
80+
# This can be exploited for interesting effects.
81+
>>> under_words = ['under', 'current', 'sea', 'pin', 'dog', 'lay']
82+
>>> separator = ' ⤴️ under'
83+
>>> separator.join(under_words)
84+
'under ⤴️ undercurrent ⤴️ undersea ⤴️ underpin ⤴️ underdog ⤴️ underlay'
85+
86+
# The seperator can be composed different ways, as long as the result is a string.
87+
>>> upper_words = ['upper', 'crust', 'case', 'classmen', 'most', 'cut']
88+
>>> separator = ' 🌟 ' + upper_words[0]
89+
>>> separator.join(upper_words)
90+
'upper 🌟 uppercrust 🌟 uppercase 🌟 upperclassmen 🌟 uppermost 🌟 uppercut'
6391
```
6492

93+
6594
Code points within a `str` can be referenced by `0-based index` number from the left:
6695

6796

0 commit comments

Comments
 (0)