This question already has an answer here:
这个问题在这里已有答案:
- How do I create a variable number of variables? 13 answers
如何创建可变数量的变量? 13个答案
How can I separate values from a multi-dimensional list, and assign them to individual variables using a for-loop? ( Without knowing the number of lists in the list ).
如何从多维列表中分离值,并使用for循环将它们分配给各个变量? (不知道列表中的列表数量)。
list = [ [ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ] , [ 7 , 8 ] , [ 9 , 10 ] ]
list1 = [ ]
list2 = [ ]
list3 = [ ]
for i in range(len(listA)):
list1.append(listA[0])
output list1
:
[ 1 , 2 ]
output list2
:
[ 3 , 4 ]
1 个解决方案
#1
-1
Well, think about it. You already have what you need:
好吧,想一想。你已经拥有了你需要的东西:
list1 = list[0]
list2 = list[1]
... and so on.
#1
-1
Well, think about it. You already have what you need:
好吧,想一想。你已经拥有了你需要的东西:
list1 = list[0]
list2 = list[1]
... and so on.