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
'develop > Python' 카테고리의 다른 글
[프로그래머스/파이썬] 잘라서 배열로 저장하기 (0) | 2023.02.28 |
---|---|
[프로그래머스/파이썬] 문자열 밀기 (0) | 2023.02.27 |
[파이썬/Python] 순열(permutation)과 조합(combination) (0) | 2023.02.25 |
[프로그래머스/파이썬] 주사위의 개수 (0) | 2023.02.25 |
[프로그래머스/파이썬] n의 배수 고르기 (0) | 2023.02.25 |