I’m running into a problem which I cannot solve online- all answers I’ve found only allow the appending to happen once since it just keeps repeating the same action.
For context: If a string isn’t 128 lines long- I want to pad it out to reach 128. All padding should add 00 then move to the next line. For example:
JavaScript
x
9
1
01
2
01
3
02
4
03
5
05
6
06
7
09
8
01
9
Then with padding should become
JavaScript
1
13
13
1
01
2
01
3
02
4
03
5
05
6
06
7
09
8
01
9
00
10
00
11
00
12
00 UP TO 128 lines
13
Hope that explains what I need to do.
I’ve tried using .join and .ljust/.rjust. inside a while loop. The while loop is:
JavaScript
1
4
1
while count != 129:
2
padding.join("00n")
3
count += 1
4
However it only ever prints out 00. Any advice is appreciated. Thank you!
Advertisement
Answer
JavaScript
1
3
1
your_string = "01n01n02n03n05n06n09n01n"
2
new_string = your_string + (128 - len(your_string.split())) * "01n"
3