Reputation: 1781
Suppose I have the following Python multi dimensional list
oldList = [['a', '0', '1', '2'], ['b', '3', '4'], ['c', '5']]
How can I get each list within this multi d list?
i.e. newList1 = ['a', '0', '1', '2']
newList2 = ['b', '3', '4']
newList3 = ['c', '5']
Upvotes: 0
Views: 230
Reputation: 117400
You can use values unpacking:
oldList = [['a', '0', '1', '2'], ['b', '3', '4'], ['c', '5']]
newList1, newlist2, newlist3 = oldList
Upvotes: 4
Reputation: 14098
You can use use indexing with oldList:
newList1 = oldList[0]
newList2 = oldList[1]
newList3 = oldList[2]
Upvotes: 1
Reputation: 280973
You already have each sublist. They're in the list. If you want the first one, you could use
oldList[0]
or if you know there will be 3 sublists and you want all of them, you could use
a, b, c = oldList
or if you want to iterate over them, you could use
for sublist in oldList:
do_stuff_with(sublist)
Iteration is probably what you want.
Upvotes: 5