Understanding Strings as Sequences
A list of characters is fundamentally different from a string, even though both are sequences.
One Sequence, Different Structures
A string is a sequence of text characters. A list of characters is also a sequence, but it is a different kind of structure. The difference matters because your goal determines how the text should be represented: use list() when you need individual characters, split() when you need words or larger segments, and join() when you need to build one string from several string elements.
Both representations preserve sequence order, but they do not represent the sequence in the same structural form.
Mapping Characters with list()
Call list() with a string when the desired result is one list element for each individual character. The characters remain in their original sequence order, so the first character occupies the first list position, the second character occupies the second position, and so on.
['h', 'e', 'l', 'l', 'o']Splitting Words and Segments
Use the split() method when the desired result is a list of words or larger segments. A delimiter identifies where one segment ends and the next begins. The delimiter may be supplied to split() so the string is divided at that chosen boundary.
['red', 'green', 'blue']Choosing a Segment Boundary
Turn the text "2026-09-27" into separate segments using the hyphen as the delimiter.
Identify the boundary: The hyphen separates the larger pieces of text.
Apply split(): Use the hyphen as the delimiter passed to split().
Read the result: The result is a list containing the segments on either side of each hyphen.
['2026', '09', '27']
Rebuilding Text with join()
Use join() to combine a list of strings into one string. The separator is the string on which join() is called, and that separator is placed between the list elements as they are combined.
red, green, blueSelecting the Right Conversion
Choose the operation by asking what each resulting element should represent. If an element should represent one character, use list(). If an element should represent a word or segment separated by a delimiter, use split(). If you already have string elements and want one finished string, use join().
| Processing goal | Operation | Result structure |
|---|---|---|
| Work with individual characters | list(string) | A list of character elements |
| Separate words or segments | string.split(delimiter) | A list of text segments |
| Build one string from string elements | separator.join(list_of_strings) | One combined string |
Match the operation to the structure you need.
Mistakes Beginners Make
Using list() when the goal is to separate words or segments
list() produces individual characters, including the commas, rather than larger segments.
Fix:
Use "red,green,blue".split(",") when commas define the segment boundaries.Using split() when the goal is to obtain individual characters
split() is intended to break text into words or segments, not to express the character-by-character conversion.
Fix:
Use list("hello") for a list of individual characters.Calling join() on the list
join() is called on the separator string, not on the list.
Fix:
Write ",".join(["red", "green"]).Forgetting that the separator controls the rebuilt text
An empty separator places nothing between the elements.
Fix:
Choose the separator that matches the desired output, such as ", " or " ".
Practice the Choice
For each goal, choose list(), split(), or join(): obtain each character from "code"; separate "one|two|three" at the vertical bar; combine ["one", "two", "three"] with a single space between elements.
Hints
- Ask whether the desired elements are characters, larger segments, or an already existing list of strings.
- For join(), remember that the separator appears before .join().
Checking the Three Goals
Select the operation for each of the three text-processing tasks.
Characters: The target elements are individual characters, so use list("code").
Segments: The vertical bar marks the boundaries between segments, so use "one|two|three".split("|").
Rebuilt text: The input is already a list of strings, and a space must be placed between elements, so use " ".join(["one", "two", "three"]).
list("code") produces ['c', 'o', 'd', 'e']; splitting produces ['one', 'two', 'three']; joining with a space produces "one two three".
Key Takeaways
- A string and a list of characters are both sequences, but they are different structures.
- Use list() to convert a string into individual character elements.
- Use split() to divide a string into words or segments at a delimiter.
- Use join() to combine a list of strings, with the separator placed between elements.
- Remember that join() is called on the separator string, not on the list.
Key Takeaways
- Use list() for character-level conversion.
- Use split() when delimiters should divide text into words or segments.
- Use join() to rebuild one string from a list of strings.
- Choose the operation according to the structure your next processing step requires.
- Call join() on the separator string.