Do you simply want to turn single characters into a list, or do you want to tokenize the input, i.e. turn 57+23 into ["57", "+", "23"]?
- Håvard
5 Answers
20
votes
list('5+6')
returns
['5', '+', '6']
2
votes
Yes, very simply:
>>> s = "5+6"
>>> list(s)
['5', '+', '6']
1
votes
Using map inbuilt list creation to work
Code:
map(None,"sart")
Output:
['s', 'a', 'r', 't']
1
votes
You can also use list comprehension like:
lst = [x for x in "5+6"]
print(lst)
0
votes
in python 3
you could make this ...
>>> s = 'bioinform'
>>> s
'bioinform'
>>> w = list(s)
>>> w
['b', 'i', 'o', 'i', 'n', 'f', 'o', 'r', 'm']
>>>
but if you give list any value will give you an error so you should restart your IDLE
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more
57+23
into["57", "+", "23"]
? - Håvard