코딩테스트
프로그래머스 삼총사 PYTHON
choyou831
2024. 7. 25. 11:52

import itertools
def solution(number):
answer = []
result = []
count = 0
combination = itertools.combinations(number,3)
for combo in combination:
answer.append(combo)
for i in range(len(answer)):
result.append(sum(answer[i]))
count = result.count(0)
return count
number list에서 3가지수를 뽑아서 3가지수의 합의 개수를 return 하는 문제이다.
여기서 살짝 어려웠던점이 어떻게 3가를 뽑을것이었다.
하지만 파이썬에는 itertools이라는 모듈이 있다.
itertools를 사용하면 조합을 쉽게 표현할수있다.