aboutsummaryrefslogtreecommitdiff
path: root/challenge-008/paulo-custodio/python/ch-2.py
blob: fc6bb3acd44200106060a1f9154cd0bd15d9b83c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python3

# Challenge 008
#
# Challenge #2
# Write a function, 'center', whose argument is a list of strings, which will
# be lines of text. The function should insert spaces at the beginning of the
# lines of text so that if they were printed, the text would be centered, and
# return the modified lines.

import sys

def center(lines):
    max_len = max([len(x) for x in lines])
    for i in range(len(lines)):
        lines[i] = " "*int((max_len-len(lines[i]))/2) + lines[i]
    return lines

lines = center(sys.argv[1:])
for line in lines:
    print(line)