假设的输入数据
假设 path
变量如下:
path = ['path', ['10515194', '_derivationally_related_form', '00265386', '_derivationally_related_form', '00800940', '_hypernym', '00798245', '_derivationally_related_form', '02589576']]
示例代码
为了更清楚地展示这些操作,我们可以编写一个简单的示例代码来打印每个中间结果:
path = ['path', ['10515194', '_derivationally_related_form', '00265386', '_derivationally_related_form', '00800940', '_hypernym', '00798245', '_derivationally_related_form', '02589576']]
# 获取路径的第一个实体
first_entity = path[1][0]
print("第一个实体:", first_entity)
# 获取路径中的中间关系和实体
middle_relations_entities = path[1][1:-1]
print("中间关系和实体:", middle_relations_entities)
# 获取路径的最后一个实体
last_entity = path[1][-1]
print("最后一个实体:", last_entity)
输出结果
第一个实体: 10515194
中间关系和实体: ['_derivationally_related_form', '00265386', '_derivationally_related_form', '00800940', '_hypernym', '00798245', '_derivationally_related_form']
最后一个实体: 02589576