Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions exercises/concept/little-sisters-vocab/.docs/hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ There's four activities in the assignment, each with a set of text or words to w

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

## 3. Remove a suffix from a word

Expand Down
31 changes: 30 additions & 1 deletion exercises/concept/little-sisters-vocab/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ If a `list`, `tuple`, `set` or other collection of individual strings needs to b

```python
# str.join() makes a new string from the iterables elements.
>>> chickens = ["hen", "egg", "rooster"]
>>> chickens = ["hen", "egg", "rooster"] #lists are iterable
>>> ' '.join(chickens)
'hen egg rooster'

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

>>> ' 🌿 '.join(chickens)
'hen 🌿 egg 🌿 rooster'


# Any iterable can be used as input.
>>> flowers = ("rose", "daisy", "carnation") #tuples are iterable
>>> '*-*'.join(flowers)
'rose*-*daisy*-*carnation'

>>> flowers = {"rose", "daisy", "carnation"} #sets are iterable, but output order is not guaranteed.
>>> '*-*'.join(flowers)
'rose*-*carnation*-*daisy'

>>> phrase = "This is my string" #strings are iterable, but be careful!
>>> '..'.join(phrase)
'T..h..i..s.. ..i..s.. ..m..y.. ..s..t..r..i..n..g'


# Separators are inserted **between** elements, but can be any string (including spaces).
# This can be exploited for interesting effects.
>>> under_words = ['under', 'current', 'sea', 'pin', 'dog', 'lay']
>>> separator = ' ⤴️ under'
>>> separator.join(under_words)
'under ⤴️ undercurrent ⤴️ undersea ⤴️ underpin ⤴️ underdog ⤴️ underlay'

# The seperator can be composed different ways, as long as the result is a string.
>>> upper_words = ['upper', 'crust', 'case', 'classmen', 'most', 'cut']
>>> separator = ' 🌟 ' + upper_words[0]
>>> separator.join(upper_words)
'upper 🌟 uppercrust 🌟 uppercase 🌟 upperclassmen 🌟 uppermost 🌟 uppercut'
```


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


Expand Down
Loading