python - 将字符串转换为python列表2

时间:2014-09-09 14:55:31

标签: python

我想在python中转换字符串

INPUT : 
s = ["'UIS006538'"]

我希望输出

OUTPUT :
s = ['UIS006538']

我该怎么做?

3 个答案:

答案 0 :(得分:1)

对于您的输入,您可以删除字符'

>>> s[0].strip("'")
'UIS006538'
>>> [i.strip("'") for i in s]
['UIS006538']

您也可以使用eval来获取所有此类字符串

>>> [eval(i) for i in s]
['UIS006538']    

答案 1 :(得分:0)

In [1]: s = ["'UIS006538'"]

In [2]: s = [s.pop().strip("'")]

In [3]: s
Out[3]: ['UIS006538']

简短的方法:

In [4]: s = ["'UIS006538'".strip("'")]

In [5]: s
Out[5]: ['UIS006538']

答案 2 :(得分:0)

您可以使用filter,如下所示:

s = [filter(lambda x: x != "'", s[0])]