-2

is there a way to extract a text from a string, by searching from a point until another one?

For example I have the following string:

string = {"sn":"Arsenal To Win","mn":"Match Result","ewc":"1/1 1","cid":9281870353,"prt":"CP","ewf":"1.0","epr":"2.12","prices":{"0":"28/25","1":"2.12","2":"+112","3":"1.12","4":"-0.893","5":"1.12"}}

and what i would like to extract is the first value 2.12, between "epr" and "prices"

I tried many options, for example: line.startswith("epr") but It doesn't work well, so the most simple what i tried, without write too much line of code is:

test = string[103:108]
print test

The problem is it's not dynamic, is there a dynamic way to do it?

Thanks a lot for your help!!!!

Lord
  • 153
  • 1
  • 4
  • 15

1 Answers1

0

Your object is not a string, but a dictionary. The 2.12 is not “between” the 'epr' and the 'prices'; it is bound to the 'epr' only, and since dictionaries are unordered, it is not logically “followed” by 'prices' anyway. If you want to access the 2.12, that’s simply

string['epr']
taylor swift
  • 2,039
  • 1
  • 15
  • 29