Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中将列表动态分解为变量_Python_Reflection_List_Itertools - Fatal编程技术网

在Python中将列表动态分解为变量

在Python中将列表动态分解为变量,python,reflection,list,itertools,Python,Reflection,List,Itertools,我在运行时创建了二维列表(任一维中的条目数未知)。例如: long_list = [ [2, 3, 6], [3, 7, 9] ] 我想通过从long_列表中的每个列表中获取第I个条目来遍历它: for entry in long_list.iter(): #entry will be [2, 3] then [3, 7] then [6, 9] 我知道Python的itertools.izip_longest()方法可以做到这一点。除了它为每个列表接受不同的变量之外 itertoo

我在运行时创建了二维列表(任一维中的条目数未知)。例如:

long_list = [ [2, 3, 6], [3, 7, 9] ]
我想通过从long_列表中的每个列表中获取第I个条目来遍历它:

for entry in long_list.iter():
    #entry will be [2, 3] then [3, 7] then [6, 9]
我知道Python的itertools.izip_longest()方法可以做到这一点。除了它为每个列表接受不同的变量之外

itertools.izip_longest(var1, var2, var3 ...)
那么,如何将长列表拆分为每个列表的不同变量,然后在运行时使用所有这些变量调用izip_longest()

>>> long_list = [ [2, 3, 6], [3, 7, 9] ]
>>> import itertools
>>> for i in itertools.izip_longest(*long_list):      # called zip_longest in py3k
    print(i)


(2, 3)
(3, 7)
(6, 9)
基本上,您需要在这里使用解包功能。它同样适用于
zip


基本上,您需要在这里使用解包功能。它对
zip

也同样有效。您可能应该解释*正在解压列表。您可能应该解释*正在解压列表。