문제풀이/프로그래머스
[프로그래머스][Lv1] - 두 개 뽑아서 더하기 (Python)
얄루몬
2021. 10. 17. 02:37
from itertools import combinations
def solution(numbers):
#비어있는 집합 자료형을 만들어서 결과를 받을 것이다.
answer = set()
# 넘버 리스트 안에 2개의 요소로 구할 수 있는 모든 조합을 반환하는 함수
for i in list(combinations(numbers,2)):
#반환 받은 조합 i(1,1이라면) 둘을 더해주어야 하니까 더한값을 돌려준다.
answer.add(sum(i))
return sorted(answer)
from itertools import combinations
def solution(numbers):
return sorted(list(set([sum([i,j]) for i, j in combinations(numbers,2)])))
# 진짜 어메이징하다.