简体   繁体   English

嵌套列表中的嵌套列表 - Python?

[英]Nested List within Nested List- Python?

I am a little bit new to python and I have this issue that I tried looking for the answer but I cannot seem to find it.我对 python 有点陌生,我遇到了这个问题,我试图寻找答案,但似乎找不到。 Basically, I am using MW.com's API to create a word dictionary and they have their data within nested lists.基本上,我正在使用 MW.com 的 API 创建一个字典,并且它们的数据位于嵌套列表中。 How would I be able to get the information from the nested lists?我如何能够从嵌套列表中获取信息? For example, in the list below in would want to get "{bc}known or understood only by a small group of people {bc}{sx|esoteric||}" , "We have, however, tried to shy away from the super-scientific words—they're just too {wi}inside baseball{/wi} unless you're an actual distiller."例如,在下面的列表中,想要让"{bc}known or understood only by a small group of people {bc}{sx|esoteric||}""We have, however, tried to shy away from the super-scientific words—they're just too {wi}inside baseball{/wi} unless you're an actual distiller." , etc. , ETC。

I tried using an index, but the issue is, every word has a different index (ie just because it is located in index y in this word, doesn't mean it would be in the same index for another word).我尝试使用索引,但问题是,每个单词都有不同的索引(即仅仅因为它位于该单词的索引 y 中,并不意味着它会在另一个单词的同一索引中)。 So I would need some sort of way to unwrap the list with different indexes (if that makes sense).所以我需要某种方法来解开具有不同索引的列表(如果这有意义的话)。

[[['sense',
   {'dt': [['text',
            '{bc}known or understood only by a small group of people '
            '{bc}{sx|esoteric||} '],
           ['vis',
            [{'aq': {'auth': 'Gillian Flynn'},
              't': '"Nick, even I don\'t understand those clues," Go said. '
                   '"They\'re all {wi}inside baseball{/wi} between you and Amy '
                   '… "'},
             {'aq': {'auth': 'Deb Amien'},
              't': 'It might be a bit {wi}inside baseball{/wi} to some, but I '
                   'love it when crossword constructors poke fun at '
                   'puzzle-making conventions.'},
             {'aq': {'auth': 'Zach Johnston'},
              't': 'We have, however, tried to shy away from the '
                   "super-scientific words—they're just too {wi}inside "
                   "baseball{/wi} unless you're an actual distiller."},
             {'aq': {'auth': 'Dan McGowan'},
              't': 'This is very {wi}inside baseball{/wi}, but the House Rules '
                   'Committee meets today to consider a series of rule changes '
                   'for the 2021 and 2022 legislative sessions.'},
             {'aq': {'auth': 'Brandon Katz'},
              't': 'Earnings reports are always a bit dry and {wi}inside '
                   'baseball{/wi} for the casual entertainment industry '
                   'observer.'}]]]}]]]
data = [[['sense', {'dt': [['text', '{bc}known or understood only by a small group of people {bc}{sx|esoteric||} '], ['vis', [{'t': '"Nick, even I don\'t understand those clues," Go said. "They\'re all {wi}inside baseball{/wi} between you and Amy … "', 'aq': {'auth': 'Gillian Flynn'}}, {'t': 'It might be a bit {wi}inside baseball{/wi} to some, but I love it when crossword constructors poke fun at puzzle-making conventions.', 'aq': {'auth': 'Deb Amien'}}, {'t': "We have, however, tried to shy away from the super-scientific words—they're just too {wi}inside baseball{/wi} unless you're an actual distiller.", 'aq': {'auth': 'Zach Johnston'}}, {'t': 'This is very {wi}inside baseball{/wi}, but the House Rules Committee meets today to consider a series of rule changes for the 2021 and 2022 legislative sessions.', 'aq': {'auth': 'Dan McGowan'}}, {'t': 'Earnings reports are always a bit dry and {wi}inside baseball{/wi} for the casual entertainment industry observer.', 'aq': {'auth': 'Brandon Katz'}}]]]}]]]

data_reduced = data[0][0][1]['dt']

// '{bc}known or understood only by a small group of people {bc}{sx|esoteric||} '
text = data_reduced[0][1]

// ['"Nick, even I don\'t understand those clues," Go said. "They\'re all {wi}inside baseball{/wi} between you and Amy … "', 'It might be a bit {wi}inside baseball{/wi} to some, but I love it when crossword constructors poke fun at puzzle-making conventions.', "We have, however, tried to shy away from the super-scientific words—they're just too {wi}inside baseball{/wi} unless you're an actual distiller.", 'This is very {wi}inside baseball{/wi}, but the House Rules Committee meets today to consider a series of rule changes for the 2021 and 2022 legislative sessions.', 'Earnings reports are always a bit dry and {wi}inside baseball{/wi} for the casual entertainment industry observer.']
vises = [d['t'] for d in data_reduced[1][1]]

text_n_vises = [text] + vises

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM