Python 如何在新窗口中显示字典列表中每个字典的最后一项?

Python 如何在新窗口中显示字典列表中每个字典的最后一项?,python,list,dictionary,Python,List,Dictionary,尝试使用TrialHandler编写一个实验,我成功地制作并打印了以下形式的词典列表: [ { 'sentence': 'I am currently working', 'variable1': 1, 'variable2': 10 }, { 'sentence': 'How are you today?', 'variable1': 2, 'variable2': 20

尝试使用TrialHandler编写一个实验,我成功地制作并打印了以下形式的词典列表:

[
    {
        'sentence': 'I am currently working',
        'variable1': 1,
        'variable2': 10
    },
    {
        'sentence': 'How are you today?',
        'variable1': 2,
        'variable2': 20
    }, # ... etc.
]

每本词典都描述了试验的特点。整个词典列表包含了实验的所有试验。是否可以选择每本词典的句子部分并在新窗口中逐个显示句子?

您可以使用列表理解获得句子列表:

listOfDict = [{'variable1':1, 'variable2':10, 'sentence':'I am currently working'},
              {'variable1':2, 'variable2':20, 'sentence':'How are you today?'}]

sentences = [d['sentence'] for d in listOfDict]
print(sentences)
打印出:

['I am currently working', 'How are you today?']
看看这个:

>>> d = [
...     {
...         'sentence': 'I am currently working',
...         'variable1': 1,
...         'variable2': 10
...     },
...     {
...         'sentence': 'How are you today?',
...         'variable1': 2,
...         'variable2': 20
...     },
... ]
>>>
>>> "\n".join(x['sentence'] for x in d)
'I am currently working\nHow are you today?'
>>> print "\n".join(x['sentence'] for x in d)
I am currently working
How are you today?
>>>