3

Let's say I have a string like 'banana' and I'd to convert it into a list ['banana'], in python. I tried ''.join(list('banana')) and other tricks, and I'm still back to square one! Thanks

2 Answers 2

7

Why not [mystring]? It uses the list literal to create a list with just the value of mystring inside.

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

2 Comments

Thanks! I was just being too tired, I guess. Having being working for 8 straight hours. This is probably a proof that I should get some rest now.
Go to sleep bro. Sleep deprivation never made you think clearer. Just makes my name more ironic doesn't it?
3

Try the following in a python shell:

>>> lst = ["banana"]
>>> type(lst)
<type 'list'>

Then, you can append some other fruits :

>>> lst.append('cherry')
>>> print "\n".join(lst)
banana
cherry

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.