How do you convert a string into a list?
Say the string is like text = \"a,b,c\"
. After the conversion, text == [\'a\', \'b\', \'c\']
and h
# to strip `,` and `.` from a string ->
>>> 'a,b,c.'.translate(None, ',.')
'abc'
You should use the built-in translate
method for strings.
Type help('abc'.translate)
at Python shell for more info.
Like this:
>>> text = 'a,b,c'
>>> text = text.split(',')
>>> text
[ 'a', 'b', 'c' ]
Alternatively, you can use eval()
if you trust the string to be safe:
>>> text = 'a,b,c'
>>> text = eval('[' + text + ']')