A delimiter is a character or sequence that marks boundaries between parts of text. In Python, a string can serve as a delimiter for joining strings, while split uses a delimiter to break text into substrings. section 2.3.2 section 2.3.3
style_settings = ["font-size=large", "font=Arial", "color=black", "align=center"] merged_style = ", ".join(style_settings) print(merged_style) # output: font-size=large, font=Arial, color=black, align=center
Use the separator string’s join method to combine iterable strings. This style-settings example inserts a comma and space between each item. section 2.3.2
Listing 2.5 Processing text data by splitting strings
processed_tasks = []
for data_line in task_data.split("\n"):
processed_task = data_line.split(",") #1
processed_tasks.append(processed_task)
print(processed_tasks)
# output the following line:
[['1001', 'Homework', '5'], ['1002', 'Laundry', '3'], ['1003', 'Grocery', '4']]
Split each line at its comma delimiter to turn task records into lists of fields. section 2.3.3
When text uses multiple delimiters, choose a simple strategy:
- Split on one delimiter, then inspect the resulting pieces and split again where needed. section 2.3.3
- Replace one delimiter with another, then split once on the consolidated delimiter. section 2.3.3










