My folder name is : east_resized_0.5
what i want is, if i see the specific word resized
in the name to take the number after, the number being any in this case 0.5
, could be 7.23
etc..
what i have done is :
path_to_east = 'data/east_resized_0.5'
resized = re.findall(r'resized',path_to_east)
if resized:
numbers = re.findall(r'\d+', path_to_east)
print(numbers)
resized = numbers[0] +'.'+ numbers [1]
print(resized)
The output will be
['0', '5']
0.5
which does give me what i want eventually but it's not a clean way to say the least and it'll get even messier when i have to make a while loop to make sure every element is in resized if for example the number is 7.23
.
How can i use regex to make my code cleaner and more efficient