최대 1 분 소요

https://school.programmers.co.kr/learn/courses/30/lessons/12950

두 행렬의 덧셈결과를 구하는 문제.

내 풀이

def solution(arr1, arr2):
    answer = []
    for i in range(len(arr1)) :
        row_result = []
        for j in range(len(arr1[0])) :
            temp = arr1[i][j] + arr2[i][j]
            row_result.append(temp)
        answer.append(row_result)
    return answer

다른 사람의 풀이 1

def solution(A, B) :
    answer = [[c + d for c, d in zip(a, b)] for a, b in zip(A, B)]
    return answer

다른 사람의 풀이 2

def solution(A, B) :
    return [list(map(sum, zip(*x))) for x in zip(A, B)]

댓글남기기