Lesson 4.5
split cuts a string into parts, join glues the parts back together:
text = "I learn python"
words = text.split() # ['I', 'learn', 'python']
print("-".join(words)) # I-learn-python
Remember the order: split is called on the string, and join on the separator:
text.split() — split the text by spaces;"-".join(words) — glue the list together with a hyphen.The right order is easy to remember: first what you call it on, then what you glue.
The text and the separator separator are set by the check. Print, in order:
print shows it;separator..split() cuts the string by spaces and returns a list.
.split("-") cuts by another separator. "-".join(list) builds the string back
together — the separator goes before the dot.