Print Sentences as a Table
Asked at Airbnb
Reported by the problem's creator, not verified
You are printing a list of sentences as a bordered text table. Each row holds width characters of text between the borders, and every sentence goes on a single row.
Write print_table(sentences, width) and return the table as a list of lines, one string per line.
Examples
Example 1
Input: sentences =
["Hello world","How are you today","Bye"], width =55Output:
["+---------------------------------------------------------+","| Hello world |","+---------------------------------------------------------+","| How are you today |","+---------------------------------------------------------+","| Bye |","+---------------------------------------------------------+"]Explanation: Each row is
|, a space, the sentence padded with spaces on the right to 55 characters, a space and|, so every row is 59 characters. Each rule is+, 57 dashes and+. One rule sits between neighbouring rows, so three sentences give seven lines.