I know the function print()
can align text to right or to left, but can I align to both sides?
Example: This text:
Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit.
Should be look like this:
Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit.
I wrote my own version here (also has a padding with "-" when many spaces in line): https://github.com/zvibazak/both_sides_align
Usage:
both_sides_align(txt, size, max_spaces=5)
txt
- text to be aligned
size
- size of the output
max_spaces
- max space to add to a line (above this number - a "-" will be added and split the word to next line)
Example:
Using this code
from both_sides_align import both_sides_align
both_sides_align(txt,60,3)
Will give this text:
Nulla luctus bibendum nulla nec efficitur. Quisque id aliq-
uam enim. Etiam non lectus id risus rhoncus condimentum.
Nam ultrices ex quis risus iaculis ullamcorper. Vivamus id
venenatis mi, et suscipit ipsum.```