Sunday, April 5, 2026
HomeLanguagesPython | SymPy Permutation.from_sequence() method

Python | SymPy Permutation.from_sequence() method

Permutation.from_sequence() : from_sequence() is a sympy Python library function that returns the permutation which is required to obtain ‘i’ from the sorted elements of ‘i’. A ‘key’ can also be passed as an argument if any custom string is required.

Syntax :
sympy.combinatorics.permutations.Permutation.from_sequence()

Return :
returns the permutation which is required to
obtain ‘i’ from the sorted elements of ‘i’

Code #1 : from_sequence() Example




# Python code explaining
# SymPy.from_sequence()
  
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
  
# Using from 
# sympy.combinatorics.permutations.Permutation.from_sequence() method 
  
# creating vectors
a = [1, 0, 0, 0]
  
b = [6, 5, 4, 3, 0, 0 ]
  
# inversion forms
print ("vector a - from_sequence form : \n", Permutation.from_sequence(a))
print ("vector b - from_sequence form : \n", Permutation.from_sequence(b))


Output :

vector a – from_sequence form :
Permutation([3, 0, 1, 2])

vector b – from_sequence form :
Permutation([5, 4, 3, 2, 0, 1])

Code #2 : from_sequence() Example – using string and key




# Python code explaining
# SymPy.from_sequence()
  
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
  
# Using from sympy.combinatorics.permutations.Permutation.from_sequence() method 
  
# creating vector
a = [2, 3, 1, 0]
  
# inverted vector of a
print ("vector a - from_sequence form : "
       Permutation.from_sequence(a))
  
# length = 5, so permutation as per that.
print ("\nstring - from_sequence form : "
       Permutation.from_sequence('GEEKS'))
  
  
# length = 5, so permutation as per that.
# defining a key
print ("\nstring - from_sequence form : "
       Permutation.from_sequence('GEEKS', key = lambda x: x.lower()))


Output :

vector a – from_sequence form : Permutation([2, 3, 1, 0])

string – from_sequence form : Permutation([2, 0, 1, 3, 4])

string – from_sequence form : Permutation([2, 0, 1, 3, 4])

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32512 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6886 POSTS0 COMMENTS
Nicole Veronica
12007 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12100 POSTS0 COMMENTS
Shaida Kate Naidoo
7015 POSTS0 COMMENTS
Ted Musemwa
7259 POSTS0 COMMENTS
Thapelo Manthata
6972 POSTS0 COMMENTS
Umr Jansen
6960 POSTS0 COMMENTS