I am trying to filter data in an array with the help of a pattern \d\.\d. The elements in the array might sometimes consist of strings as well. I try to use the re.findall function to get a list of the decimal numbers within my strings in the array but my code doesn't recognise all decimal numbers.
My code is as below -
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)
The output is only [2.7] whereas I need to also get [.3]. What change is required in my code