【发布时间】:2019-07-17 13:45:17
【问题描述】:
我有一个字符串,其中包含引号内的数值。我需要从这些以及[ 和] 中删除数值
示例字符串:texts = ['13007807', '13007779']
texts = ['13007807', '13007779']
texts.replace("'", "")
texts..strip("'")
print texts
# this will return ['13007807', '13007779']
所以我需要从字符串中提取的是:
13007807
13007779
【问题讨论】:
-
看起来你需要
int() -
嗯...
numbers = [int(s) for s in texts]做你所追求的(给定你的样本)吗?还是texts本身就是一个字符串? -
texts 是我转换为字符串的列表 texts = str(re.findall(r"\d+", texts))
标签: python regex replace split