matrix = [[1],
[1, 2],
[1, 2, 3],
[1, 2, 3, 4],
[1, 2, 3, 4, 5],
[3, 4, 5],
[2, 3, 4, 5],
]
# 现在需要将矩阵中所有的列表长度对齐到最长的列表的长度5,末尾全部用0填充
max_len = max((len(l) for l in matrix))
new_matrix = list(map(lambda l: l + [0] * (max_len - len(l)), matrix))
print(new_matrix)

相关文章:

  • 2022-12-23
  • 2021-08-06
  • 2021-09-24
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
猜你喜欢
  • 2022-01-05
  • 2022-12-23
  • 2022-01-05
  • 2022-12-23
  • 2021-10-17
  • 2022-12-23
相关资源
相似解决方案