| 134 | |
| 135 | print("Example 4") |
| 136 | class ColumnPrinter: |
| 137 | def __init__(self): |
| 138 | self.columns = [] |
| 139 | |
| 140 | def append(self, data): |
| 141 | self.columns.append(data) |
| 142 | |
| 143 | def __str__(self): |
| 144 | row_count = 1 |
| 145 | for data in self.columns: |
| 146 | row_count = max(row_count, len(data.splitlines()) + 1) |
| 147 | |
| 148 | rows = [""] * row_count |
| 149 | for j in range(row_count): |
| 150 | for i, data in enumerate(self.columns): |
| 151 | line = data.splitlines()[max(0, j - 1)] |
| 152 | if j == 0: |
| 153 | padding = " " * (len(line) // 2) |
| 154 | rows[j] += padding + str(i) + padding |
| 155 | else: |
| 156 | rows[j] += line |
| 157 | |
| 158 | if (i + 1) < len(self.columns): |
| 159 | rows[j] += " | " |
| 160 | |
| 161 | return "\n".join(rows) |
| 162 | |
| 163 | |
| 164 | logging.getLogger().setLevel(logging.ERROR) |