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))])
๋ฐ์ํ