Python - 转置不同长度的列表列表 - 3.3最简单的方法

Pho*_*nix 5 python transpose list python-3.x nonetype

a=[[1,2,3],[4,6],[7,8,9]]
Run Code Online (Sandbox Code Playgroud)

在Python 2中如果我有一个包含变量长度列表的列表,那么我可以执行以下操作:

list(map(None,*a))
Run Code Online (Sandbox Code Playgroud)

在Python 3中,似乎不接受任何类型.

在Python 3中,是否有一个生成相同结果的简单方法.

Ash*_*ary 7

你可以itertools.zip_longest在Python 3中使用:

>>> from itertools import zip_longest
>>> list(zip_longest(*a))
[(1, 4, 7), (2, 6, 8), (3, None, 9)]
Run Code Online (Sandbox Code Playgroud)