I am trying to replace some variables in a file from another file, I want only that particular variable to be replaced but not part of another variable too.
file1="0=0.49,1=0.50,2=0.12,3=0.87,4=0.88,5=0.11"
file2="((((2*(v-2))+(3*(v2)))*(0*(v-1)))+(((4*(v-2))+(5*(v2)))*(1*(v1))))"
Current result :((((0.12*(v-0.12))+(0.87*(v0.12)))*(0.49*(v-0.50)))+(((0.88*(v-0.12))+(0.11*(v0.12)))*(0.50*(v0.50))))
Desired result :((((0.12*(v-2))+(0.87*(v2)))*(0.49*(v-1)))+(((0.88*(v-2))+(0.11*(v2)))*(0.50*(v1))))
What I have tried:
file1="0=0.49,1=0.50,2=0.12,3=0.87,4=0.88,5=0.11"
file2="((((2*(v-2))+(3*(v2)))*(0*(v-1)))+(((4*(v-2))+(5*(v2)))*(1*(v1))))"
variables = {}
for equation in file1.split(","):
var, value = equation.split("=")
variables[var] = value
print(variables)
operation = [variables.get(letter, letter) for letter in file2]
op="result = " + "".join(operation)
print(op)