Given a rectangular matrix of characters, add a border of asterisks(*
) to it.
For
picture = ["abc",
"ded"]
the output should be
solution(picture) = ["*****",
"*abc*",
"*ded*",
"*****"]
[execution time limit] 4 seconds (py3)
[input] array.string picture
A non-empty array of non-empty equal-length strings.
Guaranteed constraints:
1 ≤ picture.length ≤ 100
,
1 ≤ picture[i].length ≤ 100
.
The same matrix of characters, framed with a border of asterisks of width 1
.
def solution(picture):
v_border=["*"*(len(picture[0])+2)]
with_border=["*"+x+"*" for x in picture]
return v_border+with_border+v_border
def solution(picture):
l=len(picture[0])+2
return ["*"*l]+[x.center(l,"*") for x in picture]+["*"*l]
center
가운데 정렬>>> ex_str = "hello, jack"
>>> ex_str.center(20, '#')
# '####hello, jack#####'
>>> ex_str.center(30, ' ')
# ' hello, jack '
ljust()
, rjust()
>>> ex_str = 'hello'
>>> num = 10
>>> ex_str.center(num)
>>> ex_str.ljust(num)
>>> ex_str.rjust(num)
# ' hello '
# 'hello '
# ' hello'
>>> '1'.rjust(3, '0')
>>> '1'.ljust(3, '0')
# '001'
# '100'
References