1

I have a question about converting a string to a list. I know the following:

>>str1 - "123"
>>list(string)
['1','2','3']

but how to output:

['123']
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • 1
    Does this answer your question? [How to convert string into list in python](https://stackoverflow.com/questions/54396086/how-to-convert-string-into-list-in-python) – Gino Mempin Oct 17 '20 at 00:56

3 Answers3

2

Just use braces directly:

[str1]

Or if you want to stick with list:

list((str1,))

does the same.

Cihan
  • 2,267
  • 8
  • 19
2

You can do it as follows:

list1 = [str1]
Hamza
  • 5,373
  • 3
  • 28
  • 43
0

its easy

>>>str1 = "123"
>>>"".join(str1)
['123']

or: [str1]

Aaron_ab
  • 3,450
  • 3
  • 28
  • 42
Shashwat Agrawal
  • 105
  • 1
  • 10
  • 1
    Your first answer isn't true, try to run the ```type``` command on the result. From the documentation: str.join(iterable) Return a string which is the concatenation of the strings in iterable. – Almog Oct 16 '20 at 20:19