| 196 | |
| 197 | print("Example 8") |
| 198 | class ColumnPrinter: |
| 199 | def __init__(self): |
| 200 | self.columns = [] |
| 201 | |
| 202 | def append(self, data): |
| 203 | self.columns.append(data) |
| 204 | |
| 205 | def __str__(self): |
| 206 | row_count = 1 |
| 207 | for data in self.columns: |
| 208 | row_count = max(row_count, len(data.splitlines()) + 1) |
| 209 | |
| 210 | rows = [""] * row_count |
| 211 | for j in range(row_count): |
| 212 | for i, data in enumerate(self.columns): |
| 213 | line = data.splitlines()[max(0, j - 1)] |
| 214 | if j == 0: |
| 215 | padding = " " * (len(line) // 2) |
| 216 | rows[j] += padding + str(i) + padding |
| 217 | else: |
| 218 | rows[j] += line |
| 219 | |
| 220 | if (i + 1) < len(self.columns): |
| 221 | rows[j] += " | " |
| 222 | |
| 223 | return "\n".join(rows) |
| 224 | |
| 225 | |
| 226 | columns = ColumnPrinter() |