blob: 0b0c06baa3c6b902ae791e223ff7012b9ff19fe8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from typing import List
def center(lines: List[str]) -> List[str]:
# Find the maximum length of the lines
max_length = max(len(line) for line in lines)
# Center each line by adding spaces at the beginning
centered_lines = []
for line in lines:
padding = (max_length - len(line)) // 2
centered_line = " " * padding + line
centered_lines.append(centered_line)
return centered_lines
# Test cases
lines1 = ["This", "is", "a test of the", "center function"]
expected1 = [" This", " is", " a test of the", "center function"]
assert center(lines1) == expected1
|