为什么数据结构中的元组会嵌套在列表中?

2024-10-04 07:32:42 发布

您现在位置:Python中文网/ 问答频道 /正文

("horses are too tall and they pretend to care about your feelings", {
        'entities': [(0, 6, 'ANIMAL')]
    })

我看到了这个数据结构。它是一个元组,第二个元素作为字典条目:

'entities': [(0,6, 'ANIMAL')]

我的问题是,为什么需要[]而不是更简单的形式:

   'entities': (0,6, 'ANIMAL')

Tags: andto数据结构youraretooaboutentities
1条回答
网友
1楼 · 发布于 2024-10-04 07:32:42

从单词entities的复数形式来看,很明显,数据结构的作者希望这个键是一个列表,很可能是为了将句子中的某些单词识别为已知的实体,因此可以有,例如:

("Joe loves dogs", {
        'entities': [(0, 3, 'PERSON'), (10, 14, 'ANIMAL')]
})

表示索引03中的字符表示人,索引1014中的字符表示动物。你知道吗

相关问题 更多 >