Python中的SymPy Permutation.length()
Permutation.length() : length()是一个sympy Python库函数,可以找到被permutation移动的整数的数量。
语法 : sympy.combinatorics.permutations.Permutation.length()
返回:通过排列组合移动的整数的数量
代码 #1 : length() 示例
# Python code explaining
# SymPy.Permutation.length()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.length() method
# creating Permutation
a = Permutation([[2, 0], [3, 1]])
b = Permutation([1, 3, 5, 4, 2, 0])
print ("Permutation a - length form : ", a.length())
print ("Permutation b - length form : ", b.length())
输出 :
Permutation a – length form : 4
Permutation b – length form : 6
代码#2:length()示例–二维互换法
# Python code explaining
# SymPy.Permutation.length()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.length() method
# creating Permutation
a = Permutation([[2, 4, 0],
[3, 1, 2],
[1, 5, 6]])
print ("Permutation a - length form : ", a.length())
输出 :
Permutation a – length form : 7