Development/CodingTest

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] Python ๋น„๋ฐ€์ง€๋„

Kirok Kim 2022. 1. 9. 19:28
์ „์ฒด ์ฝ”๋“œ
def solution(n, arr1, arr2):
    answer=[]
    for i,j in zip(arr1,arr2):
        tmp=str(bin(i|j)[2:])
        tmp=tmp.zfill(n)
        tmp=tmp.replace('1','#')
        tmp=tmp.replace('0',' ')
        answer.append(tmp)
    return answer
๋ฌธ์ž์—ด ์ •๋ ฌ
  • ljust,center,rjust,zfill()
st.ljust(x)  ์ขŒ์ธก ์ •๋ ฌ
st.center(x) ๊ฐ€์šด๋ฐ ์ •๋ ฌ
st.rjust(x)  ์šฐ์ธก ์ •๋ ฌ

"01".rjsut(4,'0')
>>>"0001"

"01".ljsut(4,'0')
>>>"0100"

"2".zfill(4)
>>> "0002"

"512".zfill(4)
>>>"0512"
ํ•œ ์ค„ ์ฝ”๋“œ....
solution = lambda n, arr1, arr2: ([''.join(map(lambda x: '#' if x=='1' else ' ', "{0:b}".format(row).zfill(n))) for row in (a|b for a, b in zip(arr1, arr2))])

 

 

๋ฐ˜์‘ํ˜•