Given an array of strings and a character to be used as a border, output the frame with the content inside.
https://www.codewars.com/kata/create-a-frame
一道简单的字符串题。
先找出最长的单词,确定输出的frame 的宽度,然后逐行将内容按给定格式填到frame里,最后输出frame。
def frame(text, char):
max_l = 0
for item in text:
if len(item) > max_l:
max_l = len(item)
frame_l = max_l + 4
frame = char * frame_l + "\n"
temp_frame = ""
for i in range(len(text)):
temp_frame = char + " " + text[i] + " " * (max_l - len(text[i])) + " " + char + "\n"
frame = frame + temp_frame
frame += char * frame_l
return frame