I have string as:
myString = 'example'
How can I convert it into a list as :
lst = ['example']
in an efficient way?
I have string as:
myString = 'example'
How can I convert it into a list as :
lst = ['example']
in an efficient way?
The most natural way is correct:
mystr = 'example'
lst = [mystr]
Also, don't name your variables str
; it overrides the built-in str
.
you can use the append() function to achieve that:
lst = []
str = 'example'
lst.append(str)
str='example'
l=list(str)
Now l will contain ['e', 'x', 'a', 'm', 'p', 'l', 'e']