刚刚开始使用python,知道知道我什么都不知道。我想找到另一种方式将列表分成一系列的字典。例如列表:Python:数组中的分割列表
data = ['**adjective:**', 'nice', 'kind', 'fine',
'**noun:**', 'benefit', 'profit', 'advantage', 'avail', 'welfare', 'use', 'weal',
'**adverb:**', 'well', 'nicely', 'fine', 'right', 'okay']
我将能够获得:
[{'**adjective**': ('nice', 'kind', 'fine'),
'**noun**': ('benefit', 'profit', 'advantage', 'avail', 'welfare', 'use', 'weal'),
'**adverb**': ('well', 'nicely', 'fine', 'right', 'okay')}]
不可能得到像你发布的第二个列表/字典结构。它应该更像这样:'''''形容词':['nice','kind','fine'],'名词':['benefit','profit','advantage','avail', ''''''','''','''','副词':'好','好','好','右','好']}' – 2010-12-13 18:23:08
列表是大多数语言称为数组的东西,PHP调用数组是数组和字典组合。在Python中没有'{key1:val1,val2,val3}'这样的薄弱环节。 – delnan 2010-12-13 18:23:35
您的输出不太有效。你想要{'形容词':['nice','kind'],'名词':['benefit',profit',...]}? – kevpie 2010-12-13 18:24:31