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
  • 19,150
  • 23
  • 79
  • 104
adam
  • 39
  • 7
  • 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.

chn
  • 2,222
  • 7
  • 18
2

You can do it as follows:

list1 = [str1]
Hamza
  • 4,186
  • 2
  • 21
  • 39
0

its easy

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

or: [str1]

Aaron_ab
  • 3,126
  • 3
  • 26
  • 40
  • 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