-4

I have string as:

myString = 'example'

How can I convert it into a list as :

lst = ['example'] 

in an efficient way?

shahidfoy
  • 1,951
  • 1
  • 17
  • 23
sunil shrestha
  • 27
  • 3
  • 11

3 Answers3

4

The most natural way is correct:

mystr = 'example'
lst = [mystr]

Also, don't name your variables str; it overrides the built-in str.

iz_
  • 15,923
  • 3
  • 25
  • 40
1

you can use the append() function to achieve that:

lst = []
str = 'example'

lst.append(str)
syazwanSahdom
  • 11
  • 1
  • 3
0

str='example'

l=list(str)

Now l will contain ['e', 'x', 'a', 'm', 'p', 'l', 'e']

Prasanna P
  • 64
  • 1
  • 6