How to make all lists in a list of lists the same length by adding to them

后端 未结 3 2004
谎友^
谎友^ 2021-01-18 21:53

I have a nested list which contains lists filled with strings. What I am trying to do is make each list in this nest the same length as the longest available list in that n

3条回答
  •  生来不讨喜
    2021-01-18 22:28

    You can do this,

    maxLen = max(map(len, arr))
    [row.extend(['null']*(maxLen - len(row))) for row in arr]
    

提交回复
热议问题