I've come across this problem which I have to solve by creating a function that multiplies all float numbers by a predetermined float (parameter) but the problem is I cant get it to recognize floats, only ints (recognize 2.5 as 2 and 5)
For example, the code I've seen here with 2 as a parameter would run "2.5,3.5,4.5" and result in "4.10,6.10,8.10" but I would like to end up with "5,7,9". Any ideas?
Here is the code that solves it but only for integers:
def myfunction(mystring, by):
return re.sub(
re.compile("\d+"),
lambda matchobj: str(int(matchobj.group(0))*by),
mystring
)