How to split a string into an array of characters in Python?

Adrian picture Adrian · Feb 12, 2011 · Viewed 872.3k times · Source

I've tried to look around the web for answers to splitting a string into an array of characters but I can't seem to find a simple method

str.split(//) does not seem to work like Ruby does. Is there a simple way of doing this without looping?

Answer

user225312 picture user225312 · Feb 12, 2011
>>> s = "foobar"
>>> list(s)
['f', 'o', 'o', 'b', 'a', 'r']

You need list