Reputation: 2795
I have a string str="[0,1,12]"
What is the most efficent way to strip out the "["
,"]"
, and the ","
only to leave the numbers as a list
behind? I tried .rstrip()
, but it only takes the characters at end of the string.
Upvotes: 1
Views: 120
Reputation: 298582
Evaluate the string into a list
:
from ast import literal_eval
numbers = literal_eval(your_string)
Upvotes: 6