I have a STRING which contains the following:
tesla = {"number_of_shares":0, "avg_price":200}
and I want to exchange the number of shares to 3 example:
tesla = {"number_of_shares":3, "avg_price":200}
I know I could do something like this:
string = r'tesla = {"number_of_shares":0, "avg_price":200}'
new_string = string.split(":")[0] + ":3" + "," + string.split(",",1)[1]
But what I want is something like this:
string = r'tesla = {"number_of_shares":0, "avg_price":200}'
replace_function(string_before_number=r'tesla = {"number_of_shares":}', string) # replace the number which comes after r'"number_of_shares":' with 3