I have a list in Python. I don’t know exactly how long it is, but I know it’s less than 15 items long.
I want to pad it out to exactly 15 items long, appending empty strings for all the items that I need to add.
Is there an efficient way to do this in Python?
I was hoping:
myarr = myarr[:15]
might work, but it doesn’t.
Currently I have:
if len(myarr) < 15:
for i in range(15 - len(myarr)):
myarr.append('')
Any more compact suggestions?
1 Answer