【发布时间】:2018-05-08 08:56:56
【问题描述】:
我正在尝试借助模式\d\.\d 过滤数组中的数据。数组中的元素有时也可能包含字符串。我尝试使用re.findall 函数来获取数组中我的字符串中的十进制数字列表,但我的代码无法识别所有十进制数字。
我的代码如下 -
import re
import itertools
str1 = "2.7"
str2 = ".3"
str3 = "."
str4 = "2"
str5 = "sushruth"
x = [str1,str2,str3,str4,str5]
y = []
for a in x:
z = re.findall(r'\d\.\d',a)
if z:
print(z)
输出只有[2.7],而我还需要得到[.3]。我的代码需要进行哪些更改
【问题讨论】:
标签: python python-3.x