Programmers 두 개 뽑아서 더하기

Solution

from itertools import combinations

def solution(numbers):
    answer = []

    com = combinations(numbers, 2)

    for x, y in list(com):
        answer.append(x+y)

    return sorted(list(set(answer)))
  • 다른 사람 풀이
def solution(numbers):
    answer = []
    for i in range(len(numbers)):
        for j in range(i+1, len(numbers)):
            answer.append(numbers[i] + numbers[j])
    return sorted(list(set(answer)))