I am trying to find a smart way to pad a variable length string.
I grab the length of a text chunk, set up my fixed length string and index it like so:
text = 'string'
pad_seq_len = 10
text_len = len(text)
padded_text = '_'*pad_seq_len
print(padded_text)
padded_text[(pad_seq_len-text_len):pad_seq_len]
print(padded_text)
Output:
'__________'
'_____string'
Is there a shorter way to do this using negative indexing? I could try:
padded_text[-1:-pad_seq_len]
but I was wondering if there was an even better way...