Python – Convert a string to list.

It is actually pretty simple. 

str_list = list(string.rstrip())

Example: 

>>> string = ‘hello’
>>> str_list = list(string.rstrip())
>>> str_list
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
 

rstrip()returns the string value with all the end characters stripped. Useful for handling default whitespace characters.


Leave a comment