-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

3

You could unpack it directly:

a, b, c = myList
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80
0

python is easy, you can do

a,b,c=mylist
WNG
  • 3,705
  • 2
  • 22
  • 31
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
  • 69,937
  • 8
  • 61
  • 102