Some built-in to pad a list in python

前端 未结 10 1955
暗喜
暗喜 2020-11-27 14:06

I have a list of size < N and I want to pad it up to the size N with a value.

Certainly, I can use something like the following, but I feel that there sh

10条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 14:28

    I think this approach is more visual and pythonic.

    a = (a + N * [''])[:N]
    

提交回复
热议问题