Is there a zip-like function that pads to longest length in Python?

后端 未结 5 945
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 08:59

Is there a built-in function that works like zip() but that will pad the results so that the length of the resultant list is the length of the longest input rather

5条回答
  •  天命终不由人
    2020-11-22 09:10

    For Python 2.6x use itertools module's izip_longest.

    For Python 3 use zip_longest instead (no leading i).

    >>> list(itertools.izip_longest(a, b, c))
    [('a1', 'b1', 'c1'), (None, 'b2', 'c2'), (None, 'b3', None)]
    

提交回复
热议问题