python - 如何取消合并 python 列表中的列表?

标签 python list

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

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']
>>>

关于python - 如何取消合并 python 列表中的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22412839/

相关文章:

python - 尝试运行 py.test 时收集 setup.py 时出错?

Python ZeroMQ REQ/REP 客户端绑定(bind)永远等待

list - D 自定义列表移除,垃圾收集器

Python pdb——如何更改 "l"命令列出的默认行?

list - 在 Groovy 映射中获取具有重复值的键

python - 为 QListWidget 中的特定项目设置不同的颜色

python - 使用 Python 覆盖率对测试结果进行分组

python - 如何检查 Python 是否存在函数参数?

python - 如果所有值(在该行或列中)都为 None,则从二维列表中删除行或列

python - 在列表列表中查找最大重叠