https://programmers.co.kr/learn/courses/30/lessons/68644
from itertools import combinations as comb
def solution(numbers):
arr = list(comb(numbers, 2))
answer = [sum(temp) for temp in arr]
answer = sorted(list(set(answer)))
return answer
풀이
1. combinations를 이용해서 순서와 상관없이 두 가지를 뽑는 경우의 수를 리스트화 한다.
2. 해당 리스트의 합을 answer리스트로 초기화
3. answer를 집합의 성질을 이용해서 중복값을 제거하고 다시 리스트화 한 후 정렬
4. answer 반환
'Algorithm > 프로그래머스' 카테고리의 다른 글
[프로그래머스] Lv1 - 최소직사각형 (파이썬) (0) | 2022.03.19 |
---|---|
[프로그래머스] Lv1 - 2016년 (파이썬) (0) | 2022.03.19 |
[프로그래머스] Lv1 - 예산 (파이썬) (0) | 2022.03.18 |
[프로그래머스] Lv1 - 3진법 뒤집기 (파이썬) (0) | 2022.03.18 |
[프로그래머스] Lv1 - 약수의 개수와 덧셈 (파이썬) (0) | 2022.03.18 |