首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从Python中的嵌套数据结构中提取特定数据

如何从Python中的嵌套数据结构中提取特定数据
EN

Stack Overflow用户
提问于 2021-06-06 07:53:50
回答 1查看 45关注 0票数 0
代码语言:javascript
复制
['[{"word":"meaning","phonetics":[{"text":"/ˈmiːnɪŋ/","audio":"https://lex-audio.useremarkable.com/mp3/meaning_gb_1.mp3"}],"meanings":[{"partOfSpeech":"noun","definitions":[{"definition":"What '
 'is meant by a word, text, concept, or '
 'action.","synonyms":["definition","sense","explanation","denotation","connotation","interpretation","elucidation","explication"],"example":"the '
 'meaning of the Hindu word is ‘breakthrough, '
 'release’"}]},{"partOfSpeech":"adjective","definitions":[{"definition":"Intended '
 'to communicate something that is not directly '
 'expressed.","synonyms":["meaningful","significant","pointed","eloquent","expressive","pregnant","speaking","telltale","revealing","suggestive"]}]}]}]']

这是格式。

我想提取:

代码语言:javascript
复制
"meanings":[{"partOfSpeech":"noun","definitions":[{"definition":"A single distinct meaningful element of speech or writing, used with others (or sometimes alone) to form a sentence and typically shown with a space on either side when written or printed.",

我怎么做呢,用Python。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-06 08:11:59

我相信这是你想要的

代码语言:javascript
复制
import json
data = ['[{"word":"meaning","phonetics":[{"text":"/ˈmiːnɪŋ/","audio":"https://lex-audio.useremarkable.com/mp3/meaning_gb_1.mp3"}],"meanings":[{"partOfSpeech":"noun","definitions":[{"definition":"What '  'is meant by a word, text, concept, or '  'action.","synonyms":["definition","sense","explanation","denotation","connotation","interpretation","elucidation","explication"],"example":"the '  'meaning of the Hindu word is ‘breakthrough, '  'release’"}]},{"partOfSpeech":"adjective","definitions":[{"definition":"Intended '  'to communicate something that is not directly '  'expressed.","synonyms":["meaningful","significant","pointed","eloquent","expressive","pregnant","speaking","telltale","revealing","suggestive"]}]}]}]']
json_data = json.loads(data[0])
meanings = json_data[0]['meanings']
print(meanings)
# [{'partOfSpeech': 'noun', 'definitions': [{'definition': 'What is meant by a word, text, concept, or action.', 'synonyms': ['definition', 'sense', 'explanation', 'denotation', 'connotation', 'interpretation', 'elucidation', 'explication'], 'example': 'the meaning of the Hindu word is ‘breakthrough, release’'}]}, {'partOfSpeech': 'adjective', 'definitions': [{'definition': 'Intended to communicate something that is not directly expressed.', 'synonyms': ['meaningful', 'significant', 'pointed', 'eloquent', 'expressive', 'pregnant', 'speaking', 'telltale', 'revealing', 'suggestive']}]}]
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67856906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档