-4

I have string as:

myString = 'example'

How can I convert it into a list as :

lst = ['example'] 

in an efficient way?

2
  • either [s] or s.split() when s='example'. Although s.split() is much slower. Commented Jan 28, 2019 at 5:52
  • 1
    Possible duplicate of String to list in Python Commented Jan 28, 2019 at 5:53

3 Answers 3

4

The most natural way is correct:

mystr = 'example'
lst = [mystr]

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

lst = []
str = 'example'

lst.append(str)

Comments

1

str='example'

l=list(str)

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.