728x90
반응형
풀이과정
단순한 인덱스비교 사칙연산 문제. 내가 생각했던 풀이와 더 간단한 람다식 두가지 정리
import sys; input = sys.stdin.readline
chess = [1, 1, 2, 2, 2, 8]
nums = list(map(int, input().rstrip().split()))
for i in range(6):
print(chess[i]-nums[i], end=' ')
아래와 같이 람다를 사용하면 두개의 리스트에서 동일한 인덱스자리를 비교하여 연산할 수 있다.
white = list(map(int, (input().split())))
chess = [1, 1, 2, 2, 2, 8]
result = list(map(lambda x, y: y - x, white, chess))
print(*result)
728x90
반응형
'Algorithm > Baekjoon' 카테고리의 다른 글
[Baekjoon] 1068 Python (0) | 2023.08.29 |
---|---|
[Baekjoon] 1302 Python (0) | 2023.08.29 |
[Baekjoon] 1149 Python (0) | 2023.08.29 |
[Baekjoon] 2606 Python (0) | 2023.08.28 |
[Baekjoon] 9375 Python (0) | 2023.08.28 |