How do I split this string in python 2.7 keeping spaces?
Question: I am looking for a way to take a string and output it as a list with each
character split?

    
    
    >>> sentence = 'hello I am cool'
    >>> what_i_want(sentence)
    ['h', 'e', 'l', 'l', 'o', ' ', 'I', ' ', 'a', 'm', ' ', 'c', 'o', 'o', 'l']
    

However, this doesn't seem to work:

    
    
    >>> sentence = 'hello I am cool'
    >>> sentence = ' '.join(sentence).split()
    >>> print sentence
    ['h', 'e', 'l', 'l', 'o', 'I', 'a', 'm', 'c', 'o', 'o', 'l']
    

It doesn't print the space in between! Also, this doesn't work:

    
    
    >>> import re
    >>> splitter = re.compile(r'(\s+|\S+)')
    >>> sentence = 'hello I am cool'
    >>> splitter.findall(sentence)
    ['hello', ' ', 'I', ' ', 'am', ' ', 'cool']
    >>> sentence = ' '.join(sentence)
    >>> splitter.findall(sentence)
    ['h', ' ', 'e', ' ', 'l', ' ', 'l', ' ', 'o', '   ', 'i', '   ', 'a', ' ', 'm', '   ', 'a', ' ', 'j']
    

Can anyone tell me an efficient and relatively easy way to do this? Thanks in
advance!


Answer: Passing a string to
[`list`](http://docs.python.org/2/library/functions.html#list), you will get a
list of single-character strings.

    
    
    >>> sentence = 'hello I am cool'
    >>> list(sentence)
    ['h', 'e', 'l', 'l', 'o', ' ', 'I', ' ', 'a', 'm', ' ', 'c', 'o', 'o', 'l']
    

