Python中的SymPy Permutation.list()
Permutation.list() : list() 是一个 sympy Python 库函数,它将 permutation 作为一个明确的列表返回,如果大小小于 permutation 中的最大元素,可能会修剪未移动的元素。
语法 : sympy.combinatorics.permutations.Permutation.list()
返回:作为一个显式列表的包络法
代码 #1 : list() 示例
# Python code explaining
# SymPy.Permutation.list()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.list() method
# creating Permutation
a = Permutation([[2, 0], [3, 1]])
b = Permutation([1, 3, 5, 4, 2, 0])
print ("Permutation a - list form : ", a.list())
print ("Permutation b - list form : ", b.list())
输出 :
Permutation a – list form : [2, 3, 0, 1]
Permutation b – list form : [1, 3, 5, 4, 2, 0]
代码 #2 : list() 例子 – 二维互换
# Python code explaining
# SymPy.Permutation.list()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.list() method
# creating Permutation
a = Permutation([[2, 4, 0],
[3, 1, 2],
[1, 5, 6]])
print ("Permutation a - list form : ", a.list())
输出 :
Permutation a – list form : [3, 2, 4, 5, 0, 6, 1]