-5

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?

Louis Jaeckle
  • 21
  • 1
  • 1

3 Answers3

2

You could unpack it directly:

a, b, c = myList
Reblochon Masque
  • 33,202
  • 9
  • 48
  • 71
0

python is easy, you can do

a,b,c=mylist
WNG
  • 3,495
  • 2
  • 21
  • 28
0

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])
Ajax1234
  • 66,333
  • 7
  • 57
  • 95