Skip to main content
 首页 » 编程设计

python之如何取消合并 python 列表中的列表

2025年05月04日14davidwang456

我正在尝试弄清楚如何从列表中取消合并一堆列表。例如,来自

parent_list = [ [a, b, c], [d, e, f], [g, h, i] ] 

到

child_list1 = [a, b, c] 
child_list2 = [d, e, f] 
child_list3 = [g, h, i] 

请您参考如下方法:

使用unpacking :

>>> parent_list = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']] 
>>> child_list1, child_list2, child_list3 = parent_list 
>>> child_list1 
['a', 'b', 'c'] 
>>> child_list2 
['d', 'e', 'f'] 
>>> child_list3 
['g', 'h', 'i'] 
>>>