[이론] 순열과 조합

jeongjeong2·2023년 1월 22일
0

For coding test

목록 보기
18/59

순열과 조합의 사용

순열 : n개의 list에서 m개의 요소를 순서를 고려하여 뽑는 것
중복 순열 : n개의 list에서 m개의 요소를 순서를 고려하여 중복해서 뽑는 것
조합 : n개의 list에서 m개의 요소를 순서를 고려하지 않고 뽑는 것
중복 조합 : n개의 list에서 m개의 요소를 순서 고려 없이 중복해서 뽑는 것

library 사용하여 구현

import itertools
#순열
for i in itertools.permutations(list,m):
	print(i)
#중복순열
for i in intertools.product(list,m):
	print(i)
#조합
for i in intertools.combinations(list,m):
	print(i)
#중복조합
for i in intertools.combinations_with_replacement(list,m):
	print(i)

결과는 tuple 형태로 출력!

코드 구현 (후첨)

0개의 댓글