[프로그래머스/파이썬] 최댓값 만들기(2)

SMALL
from itertools import combinations
def solution(numbers):
    return max(value[0] * value[1] for value in list(combinations(numbers, 2)))

 

numbers 의 원소 중 두개를 곱하여 만들 수 있는 최댓값 구하기

itertools 라이브러리의 combinations를 사용하여 numbers의 조합을 구하고

만들어진 조합을 for문을 사용하여 값을 곱하였다.

마지막으로 곱해진 값들 중에서 가장 큰 값을 찾기 위하여 max() 함수를 사용했다.

 

 

 

[develop/Python] - [파이썬/Python] 순열(permutation)과 조합(combination)

LIST