是否可以將字典中的列表組合到一個新的密鑰中? 例如,我有一個字典設置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