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
more-itertools is a library that includes a special padded tool for this kind of problem:
import more_itertools as mit
list(mit.padded(a, "", N))
# [1, '', '', '', '']
Alternatively, more_itertools also implements Python itertools recipes including padnone and take as mentioned by @kennytm, so they don't have to be reimplemented:
list(mit.take(N, mit.padnone(a)))
# [1, None, None, None, None]
If you wish to replace the default None padding, use a list comprehension:
["" if i is None else i for i in mit.take(N, mit.padnone(a))]
# [1, '', '', '', '']