SymPy | Partition.next_lex() in Python

Partition.next_lex() : next_lex() is a sympy Python library function that returns the next integer partition, n in lexographical order. This ordering wraps around [n] if the partition is [1, …, 1].

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

Return : next integer partition, n in lexographical order



Code #1 : next_lex() Example

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code explaining
# SymPy.next_lex()
  
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.partitions import IntegerPartition
  
# Using from sympy.combinatorics.partitions.Partition.next_lex() method 
p = IntegerPartition([312, 121, 14, 5])
  
print('p : ', p)
print('\nNext Integrer : ', p.next_lex())

chevron_right


Output :

p : [312, 121, 14, 5]

Next Integrer : [312, 121, 15, 1, 1, 1, 1]

Code #2 : next_lex() Example

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code explaining
# SymPy.next_lex()
  
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.partitions import IntegerPartition
  
# Using from sympy.combinatorics.partitions.Partition.next_lex() method 
p = IntegerPartition([1, 312, 121, 14
                      34, 56, 32])
  
print('p : ', p)
print('\nNext Integrer : ', p.next_lex())

chevron_right


Output :

p : [312, 121, 56, 34, 32, 14, 1]

Next Integrer : [312, 121, 56, 34, 32, 15]



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.