Change language

Python | SymPy Partition.sort_key () method

|

Partition.sort_key (): sort_key () — nice Python library function that returns a canonical key that can be used for a string. This canonical key ordering is based on the size and the members of the section that are out of rank.

Syntax: sympy.combinatorics.partitions.Partition.sort_key ()

Return: Conoanical key which can be used for string

Code # 1: sort_key () example

# Python code explaining
# SymPy.sort_key ()

 
# import SymPy libraries

 

from sympy.utilities.iterables import default_sort_key

from sympy.combinatorics .partitions import Partition

from sympy.abc import x

 
# Using the sympy.combinatorics.partitions.Partition.sort_key () method

g = Partition ([ 134 , 322 ])

e = Partition ( list ( range ( 3 )))

k = Partition ([ 44 , x])

s = Partition ([ 3 , 4 ])

 

lst = [s, k, g + 1 , k, e]

lst.sort (key = default_sort_key); lst

Output:

[{{3, 4}}, {{44, x}}, {{44, x}}, {{134}, {322}}, {{0, 1, 2 }}]

Code # 2: sort_key () example

# Python code explaining
# SymPy.sort_key ()

 
# import SymPy libraries

 

from sympy.utilities.iterables import default_sort_key

from sympy.combinatorics.partitions import Partition

from sympy.abc  import x, y

 
# Using the sympy.combinatorics.partitions.Partition.sort_key () method

 

k = Partition ([ 44 , x, y])

s = Partition ([ 3 , 55 , 12 , 4 ])

  

lst = [k, s]

lst.sort (key = default_sort_key); lst

Output:

[{{44, x, y}}, {{3, 4, 12, 55}}]

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method