I found ljust()
and rjust()
very useful to print a string at a fixed width or fill out a Python string with spaces.
An example
print('123.00'.rjust(9))
print('123456.89'.rjust(9))
# expected output
123.00
123456.89
For your case, you case use fstring
to print
for prefix in unique:
if prefix != "":
print(f"value {prefix.ljust(3)} - num of occurrences = {string.count(str(prefix))}")
Expected Output
value a - num of occurrences = 1
value ab - num of occurrences = 1
value abc - num of occurrences = 1
value b - num of occurrences = 1
value bc - num of occurrences = 1
value bcd - num of occurrences = 1
value c - num of occurrences = 1
value cd - num of occurrences = 1
value d - num of occurrences = 1
You can change 3
to the highest length of your permutation string.