https://school.programmers.co.kr/learn/courses/30/lessons/17682
dartResult = dartResult.replace('10','k')
point = ['10' if i == 'k' else i for i in dartResult]
아래 수정한 코드의 문법이 헷갈려서 하는 문법 정리
point = ['10' if i == 'k' else i for i in dartResult]
for 문 한줄로
for i in v:
print(i)
↓ 한줄로
print([i for i in v])
※ 배열 괄호 없애고 이쁘게 출력
print(" ".join(str(i) for i in v))
if 문 한줄로
if v<5:
print(0)
else:
print(1)
↓ 한줄로
print(0 if v<5 else 1)
for + if 문 한줄로
def solution(dartResult):
score=[]
check=0
now=0
out=0
for i in range(len(dartResult)):
if out==1:
out=0
continue
if dartResult[i]=='T':
save=save*save*save
score.append(save)
now+=1
elif dartResult[i]=='D':
save=save*save
score.append(save)
now+=1
elif dartResult[i]=='S':
score.append(save)
now+=1
elif dartResult[i]=='*':
save*=2
if check>3:
pre=score[now-2]
score[now-2]=pre*2
score[now-1]=save
elif dartResult[i]=='#':
save*=-1
score[now-1]=save
else:
if dartResult[i]=='1':
if dartResult[i+1]=='0':
save=10
out=1
continue
save=int(dartResult[i])
check+=1
return sum(score)
def solution(dartResult):
point = []
answer = []
dartResult = dartResult.replace('10','k')
point = ['10' if i == 'k' else i for i in dartResult]
print(point)
i = -1
sdt = ['S', 'D', 'T']
for j in point:
if j in sdt :
answer[i] = answer[i] ** (sdt.index(j)+1)
elif j == '*':
answer[i] = answer[i] * 2
if i != 0 :
answer[i - 1] = answer[i - 1] * 2
elif j == '#':
answer[i] = answer[i] * (-1)
else:
answer.append(int(j))
i += 1
return sum(answer)