상상쓰

[프로그래머스] 내적 본문

Coding Test

[프로그래머스] 내적

상상쓰 2021. 10. 22. 23:58

https://programmers.co.kr/learn/courses/30/lessons/70128

 

코딩테스트 연습 - 내적

길이가 같은 두 1차원 정수 배열 a, b가 매개변수로 주어집니다. a와 b의 내적을 return 하도록 solution 함수를 완성해주세요. 이때, a와 b의 내적은 a[0]*b[0] + a[1]*b[1] + ... + a[n-1]*b[n-1] 입니다. (n은 a, b의

programmers.co.kr

 

굿밤!

 

def solution(a, b):
    return sum(list(map(lambda x : x[0] * x[1], zip(a, b))))
    
print(solution([1, 2, 3, 4], [-3, -1, 0, 2])) # 3
Comments