Notice
Recent Posts
Link
- Today
- Total
hye-log
[프로그래머스]내적(Python) 본문
0. 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/70128
1. 문제 설명
1) 두 배열의 각 요소의 곱의 합 구하기
2. 입출력
# input
a = [1, 2, 3, 4]
b = [-3, -1, 0, 2]
# output
answer = 3
3. 코드
1) 첫 번째 코드
def solution(a, b):
# a, b : 내적할 두 배열
answer = 0
answer = sum([i*j for (i, j) in zip(a, b)])
return answer
실행 결과
4. 알게된 점
1) zip 함수의 사용
a = [1, 2, 3, 4]
b = [-3, -1, 0, 2]
for i in zip(a, b):
print(i)
# (1, -3)
# (2, -1)
# (3, 0)
# (4, 2)
5. Github
https://github.com/iihye/Algorithm/blob/main/Programmers/dot_product.py
728x90
'CodingTest > Programmers' 카테고리의 다른 글
[프로그래머스]폰켓몬(Python) (0) | 2022.08.09 |
---|---|
[프로그래머스]소수 만들기(Python) (0) | 2022.08.09 |
[프로그래머스]음양 더하기(Python) (0) | 2022.07.20 |
[프로그래머스]없는 숫자 더하기(Python) (0) | 2022.07.19 |
[프로그래머스]키패드 누르기(Python) (0) | 2022.07.18 |
Comments