Written by
최태열
on
on
[Python][프로그래머스][Level1] 두 개 뽑아서 더하기
[Python][프로그래머스][Level1] 두 개 뽑아서 더하기
코드
from itertools import combinations
def solution(numbers):
return sorted(list(set([sum(com) for com in combinations(numbers,2)])))
조합을 활용한 문제다.
combinations 라이브러리를 활용해 2개씩 뽑고 그 덧셈을 배열에 저장한다.
문제의 요구사항에서 오름차순으로 담으라고 했으므로 정렬까지 해주면 된다.
Discussion and feedback