と の位置を取得しようとして<
いますが、これはこのようなものに埋め込まれている場合に>
現実的です。tag
<tag "510270">calculate</>
次のような文があります。
sentence = "After six weeks and seventeen tentative approaches the only serious
tender came from Daniel. He had offered a paltry #2 a week for the one-time
woodman's home, sane enough in this, at least, to <tag "510270">calculate</>
safety to the nearest new penny piece. "
sentence2 = "After six weeks and seventeen tentative approaches the only serious
tender came from Daniel. He had offered a paltry #2 a week for the one-time
woodman's < home, sane enough in this, at least, to <tag "510270">calculate</>
safety to the nearest new penny > piece. "
sentence3 = "After six weeks and seventeen tentative approaches the only serious
tender came from Daniel. He had offered a paltry #2 a week for the one-time
woodman's > home, sane enough in this, at least, to <tag "510270">calculate</>
safety to the nearest new penny < piece. "
cfrom と incfrom を の 1 番目と 2 番目の位置に<
する<tag "XXXX">...</>
必要があり、cto と incto を の 2 番目と 1 番目の位置にする必要があり>
ます。<tag "XXXX">...</>
センテンス 2 やセンテンス 3 のようなセンテンスに対しても、どのように実行できます<
か?>
<tag "XXXX">...</>
文1の場合、私は単純にこれを行うことができます:
cfrom,cto = 0,0
for i,c in enumerate(sentence1):
if c == "<":
cfrom == i
break
for i,c in enumerate(sentence1.reverse):
if c == ">":
cto == len(sentence)-i
break
incfrom incto = 0,0
fromtrigger, totrigger = False, False
for i,c in enumerate(sentence1[cfrom:]):
if c == ">":
incfrom = cfrom+i
break
for i,c in enumerate(sentence1[incfrom:cto]):
if c == "<":
incto = i
break