순열과 조합

HyeonWoo·2021년 2월 3일
0

파이썬

목록 보기
2/2
post-thumbnail

n!(Factorial, 팩토리얼)

1부터 자연수 n까지의 모든 수를 차례대로 곱하는 것

import math

math.factorial(5)

nPr(permutation, 순열)

이름대로 뽑아서, 줄을 세우는 상황에서 순열을 사용

순서가 있고, 중복이 없을때 사용

import itertools

arr = [1,2,3,4]
w = list(itertools.permutations(alphabet,2))

중복순열

순서대로 뽑으며, 중복을 허용할때

import itertools

arr = [1,2,3,4]
w = list(itertools.product(arr, repeat=2))

nCr(combination, 조합)

순서가 없는 순열. 즉, 그냥 전체에서 특정개수를 뽑기만 하면된다.

from itertools 

arr = [1,2,3,4]
w = list(itertools.combinations(arr,2))

중복조합

import itertools

arr = [1,2,3,4]
w = list(itertools.combinations_with_replacement(arr,2)
profile
학습 정리, 자기 개발을 위한 블로그

0개의 댓글