Home >Backend Development >Python Tutorial >Example of implementation of permutation and combination calculation operations in Python
This article mainly introduces the permutation and combination calculation operations implemented in Python, involving related functions and usage skills of Python mathematical operations. Friends in need can refer to the following
The examples in this article describe the permutation and combination calculations implemented in Python operate. Share it with everyone for your reference, the details are as follows:
1. Call scipy to calculate the specific values of the permutation and combination
>> from scipy.special import comb, perm >> perm(3, 2) 6.0 >> comb(3, 2) 3.0
2. Call itertools to obtain the number of all permutations and combinations
>> from itertools import combinations, permutations >> permutations([1, 2, 3], 2) <itertools.permutations at 0x7febfd880fc0> # 可迭代对象 >> list(permutations([1, 2, 3], 2)) [(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)] >> list(combinations([1, 2, 3], 2)) [(1, 2), (1, 3), (2, 3)]
The above is the detailed content of Example of implementation of permutation and combination calculation operations in Python. For more information, please follow other related articles on the PHP Chinese website!