>>> s = "abcde" >>> k = 2 >>> [s[i:i+k].ljust(k, "_") for i in range(0, len(s), k)] ['ab', 'cd', 'e_']