@@ -173,7 +173,7 @@ If a `list`, `tuple`, `set` or other collection of individual strings needs to b
173173
174174``` python
175175# str.join() makes a new string from the iterables elements.
176- >> > chickens = [" hen" , " egg" , " rooster" ] # lists are iterable
176+ >> > chickens = [" hen" , " egg" , " rooster" ] # Lists are iterable.
177177>> > ' ' .join(chickens)
178178' hen egg rooster'
179179
@@ -186,29 +186,29 @@ If a `list`, `tuple`, `set` or other collection of individual strings needs to b
186186
187187
188188# Any iterable can be used as input.
189- >> > flowers = (" rose" , " daisy" , " carnation" ) # tuples are iterable
189+ >> > flowers = (" rose" , " daisy" , " carnation" ) # Tuples are iterable.
190190>> > ' *-*' .join(flowers)
191191' rose*-*daisy*-*carnation'
192192
193- >> > flowers = {" rose" , " daisy" , " carnation" } # sets are iterable, but output order is not guaranteed.
193+ >> > flowers = {" rose" , " daisy" , " carnation" } # Sets are iterable, but output order is not guaranteed.
194194>> > ' *-*' .join(flowers)
195195' rose*-*carnation*-*daisy'
196196
197- >> > phrase = " This is my string" # strings are iterable, but be careful!
197+ >> > phrase = " This is my string" # Strings are iterable, but be careful!
198198>> > ' ..' .join(phrase)
199199' T..h..i..s.. ..i..s.. ..m..y.. ..s..t..r..i..n..g'
200200
201201
202202# Separators are inserted **between** elements, but can be any string (including spaces).
203203# This can be exploited for interesting effects.
204204>> > under_words = [' under' , ' current' , ' sea' , ' pin' , ' dog' , ' lay' ]
205- >> > separator = ' ⤴️ under' # note the leading space, but no trailing space.
205+ >> > separator = ' ⤴️ under' # note the leading space, but no trailing space.
206206>> > separator.join(under_words)
207207' under ⤴️ undercurrent ⤴️ undersea ⤴️ underpin ⤴️ underdog ⤴️ underlay'
208208
209209# The separator can be composed different ways, as long as the result is a string.
210210>> > upper_words = [' upper' , ' crust' , ' case' , ' classmen' , ' most' , ' cut' ]
211- >> > separator = ' 🌟 ' + upper_words[0 ] # this becomes one string, similar to ' ⤴️ under'.
211+ >> > separator = ' 🌟 ' + upper_words[0 ] # this becomes one string, similar to ' ⤴️ under'.
212212>> > separator.join(upper_words)
213213 ' upper 🌟 uppercrust 🌟 uppercase 🌟 upperclassmen 🌟 uppermost 🌟 uppercut'
214214```
0 commit comments