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

后端 未结 5 776
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  -上瘾入骨i
    2020-11-22 09:08

    Im using a 2d array but the concept is the similar using python 2.x:

    if len(set([len(p) for p in printer])) > 1:
        printer = [column+['']*(max([len(p) for p in printer])-len(column)) for column in printer]
    

提交回复
热议问题