I have a list of lists
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]
How do I do this?
I have a list of lists
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]
How do I do this?
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)
Output:
([1, 2, 3], [4, 5, 6], [7, 8, 9, 10])