Home > Backend Development > Python Tutorial > Example of implementation of permutation and combination calculation operations in Python

Example of implementation of permutation and combination calculation operations in Python

黄舟
Release: 2017-10-14 10:24:21
Original
3580 people have browsed it

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
Copy after login

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)]
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template