使用位置在 python 字符串中插入标签
我有一个 python 字符串和一个元组/元组列表,表示要标记的子序列的位置和标记的名称:
text = "This is an example"
label = (0, 4, "tag1")
# Expected result
> "<tag1>This</tag1> is an example"
另一个示例:
text = "This is a more complicated example"
labels = [(0, 7, "tag1"),
(5, 7, "tag2"),
(10, 14, "tags3")]
# Expected result
> "<tag1>This <tag2>is</tag2></tag1> a <tag3>more</tag3> complicated example"
如何在指定位置插入标记?
I have a python string and a tuple/list of tuples representing the position of the subsequence to tag and the name of the tag:
text = "This is an example"
label = (0, 4, "tag1")
# Expected result
> "<tag1>This</tag1> is an example"
Another example:
text = "This is a more complicated example"
labels = [(0, 7, "tag1"),
(5, 7, "tag2"),
(10, 14, "tags3")]
# Expected result
> "<tag1>This <tag2>is</tag2></tag1> a <tag3>more</tag3> complicated example"
How to insert a tag at the specified positions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论