Ctrl K

Chunks With Padding

Easy
Cut the string text into chunks of length size: the first chunk is the first size characters, the second is the next size, and so on. Every character lands in exactly one chunk, and the order is kept. If there are not enough characters left for the last chunk, append the character pad to its end as many times as needed to bring its length up to exactly size. Return the list of chunks in order.
Example 1
text='sunflower', size=4, pad='z' → ['sunf', 'lowe', 'rzzz']

The first two chunks are "sunf" and "lowe". Only "r" is left for the third, so it gets three "z"s.

Example 2
text='banana', size=2, pad='q' → ['ba', 'na', 'na']

The length 6 divides evenly by 2, so no padding is needed.

Example 3
text='hi', size=5, pad='o' → ['hiooo']

The text is shorter than one chunk, which gives a single chunk "hiooo".

Constraints
  • 1 ≤ len(text) ≤ 100
  • 1 ≤ size ≤ 100
  • text consists of lowercase English letters
  • pad is a single lowercase English letter
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSum of Binary Strings EasyCounting Off by Threes and Fives EasyAdding Long Numbers in Strings EasyDrone Back on the Pad EasySame Text After Erasing Easy
loading Python…
Input
text='sunflower', size=4, pad='z'
Expected
['sunf', 'lowe', 'rzzz']

Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.