| 156 | |
| 157 | print("Example 3") |
| 158 | class ColumnPrinter: |
| 159 | def __init__(self): |
| 160 | self.columns = [] |
| 161 | |
| 162 | def append(self, data): |
| 163 | self.columns.append(data) |
| 164 | |
| 165 | def __str__(self): |
| 166 | row_count = 1 |
| 167 | for data in self.columns: |
| 168 | row_count = max(row_count, len(data.splitlines()) + 1) |
| 169 | |
| 170 | rows = [""] * row_count |
| 171 | for j in range(row_count): |
| 172 | for i, data in enumerate(self.columns): |
| 173 | line = data.splitlines()[max(0, j - 1)] |
| 174 | if j == 0: |
| 175 | padding = " " * (len(line) // 2) |
| 176 | rows[j] += padding + str(i) + padding |
| 177 | else: |
| 178 | rows[j] += line |
| 179 | |
| 180 | if (i + 1) < len(self.columns): |
| 181 | rows[j] += " | " |
| 182 | |
| 183 | return "\n".join(rows) |
| 184 | |
| 185 | |
| 186 | grid = LockingGrid(5, 9) # Changed |