是否可以将字典中的列表组合到一个新的密钥中? 例如,我有一个字典设置Python,在字典中组合列表
ListDict = {
'loopone': ['oneone', 'onetwo', 'onethree'],
'looptwo': ['twoone', 'twotwo', 'twothree'],
'loopthree': ['threeone', 'threetwo', 'threethree']}
我想了一个名为“loopfour”包含从“loopone”,“looptwo”名单和“loopthree”新键
因此其名单将看起来像
['oneone', 'onetwo', 'onethree', 'twoone', 'twotwo', 'twothree', 'threeone', 'threetwo', 'threethree']
,并可以使用ListDict [ '四']调用和返回组合列表
'ListDict [ 'loopfour'] = [el for l in ListDict.values()for el in l]'。 –
列表是可变的。你想如何处理列表中的值更改的情况? – Alexander