SymPy | Python中的 Permutation.list()
Permutation.list() : list()是一个 sympy Python库函数,它以显式列表的形式返回排列,如果大小小于排列中的最大元素,可能会修剪未移动的元素。
Syntax : sympy.combinatorics.permutations.Permutation.list()
Return : permutation as an explicit 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]