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

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -