코딩 테스트 (Coding Test)
[프로그래머스] 내적
Universe_lee
2023. 1. 10. 13:44
내 코드
def solution(a, b):
return sum([a[i] * b[i] for i in range(len(a))])
살펴볼만한 코드
def solution(a, b):
return sum([x * y for x, y in zip(a, b)])
파이썬 zip 함수란?
iterable 객체를 인자로 받아 묶은 뒤 하나씩 반환
a = [1, 2, 3]
b = ['a', 'b', 'c']
for c in zip(a, b):
print(c)
-> (1, 'a'), (2, 'b'), (3, 'c')...