python - How can I make a list from the string -


is there way make string:

"i python!!!" 

a list like

['i', 'l', 'i', 'k', 'e', 'p', 'y', 't', 'h', 'o', 'n', '!', '!', '!'] 

use list comprehension:

>>> mystr = "i python!!!" >>> [c c in mystr if c != " "] ['i', 'l', 'i', 'k', 'e', 'p', 'y', 't', 'h', 'o', 'n', '!', '!', '!'] >>> [c c in mystr if not c.isspace()] # alternately ['i', 'l', 'i', 'k', 'e', 'p', 'y', 't', 'h', 'o', 'n', '!', '!', '!'] >>> 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

java - SmsManager sending message more than one -