strings.text_justification¶
Functions¶
|
Will format the string such that each line has exactly |
Module Contents¶
- strings.text_justification.text_justification(word: str, max_width: int) list ¶
Will format the string such that each line has exactly (max_width) characters and is fully (left and right) justified, and return the list of justified text.
example 1: string = “This is an example of text justification.” max_width = 16
- output = [‘This is an’,
‘example of text’, ‘justification. ‘]
>>> text_justification("This is an example of text justification.", 16) ['This is an', 'example of text', 'justification. ']
example 2: string = “Two roads diverged in a yellow wood” max_width = 16 output = [‘Two roads’,
‘diverged in a’, ‘yellow wood ‘]
>>> text_justification("Two roads diverged in a yellow wood", 16) ['Two roads', 'diverged in a', 'yellow wood ']
Time complexity: O(m*n) Space complexity: O(m*n)