How do I split a string into a list of characters?

list, python, string

Solution

Use the `list` constructor:

>>> list("foobar")
['f', 'o', 'o', 'b', 'a', 'r']

`list` builds a new list using items obtained by iterating over the input iterable. A string is an iterable -- iterating over it yields a single character at each iteration step.

Problem

How do I split a string into a list of characters? `str.split` does not work. ``` "foobar" → ['f', 'o', 'o', 'b', 'a', 'r'] ```

Original source

Related problems