split and join
split breaks a string into a list of smaller strings. join does the opposite. It puts a list of strings together into one string, with a separator (some text, like "-") between them.
title = " Learn Python Today "
words = title.strip().lower().split()
slug = "-".join(words)
print(words)
print(slug)
print("red,green,blue".split(","))
Output:
['learn', 'python', 'today']
learn-python-today
['red', 'green', 'blue']
With no argument, split() breaks the text wherever there is whitespace, such as spaces. Several spaces in a row count as one break. In the example, the words are then joined with hyphens. This makes a slug, a short form of a title that is safe to use in a web address. When you give split an argument, as in the last line, it cuts at that exact text.
The pieces are always strings, even when they look like numbers. If you need to do math with a piece, convert it to a number first.
With join, you call the method on the separator, not on the list. So " | ".join(parts) puts " | " between the parts. Every part must already be a string.
In the exercise, split a line of data into parts and join them back together.