如何拆分Python列表列表? [英] How to split up a list of lists Python?
本文介绍了如何拆分Python列表列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表列表
myList = [[1,2,3],[4,5,6],[7,8,9,10]]
我想将其分为三个单独的列表,每个列表都有自己的名称:
and I want to split it up into three separate list, each with their own name:
a = [1,2,3]
b = [4,5,6]
c = [7,8,9,10]
我该怎么做?
推荐答案
要创建新变量,可以使用globals()
:
To create new variables, you can use globals()
:
import string
myList = [[1,2,3],[4,5,6],[7,8,9,10]]
for i, value in enumerate(myList):
globals()[string.ascii_lowercase[i]] = value
print(a, b, c)
输出:
([1, 2, 3], [4, 5, 6], [7, 8, 9, 10])
这篇关于如何拆分Python列表列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文