Change language

Python | Print all string combinations from given numbers

|

Examples :

  Input:  191  Output:  aia sa  Explanation:  The Possible String digit are 1, 9 and 1 -" aia 19 and 1 -" sa  Input:  1119  Output:  aaai aas aki kai ks 

Suitable :

  • Get a string and find the entire list of combinations in the specified order.
  • Find a list whose integers are in the range 0 to 25.
  • Convert integers to alphabets.
  • Sort this in lexicographic order.

# Python program to print the entire line
# combination of the given numbers

 
# Function for finding a combination

def Number_to_String (String):

 

# line length

  length = len (String)

 

  # temporary lists

temp1 = []

temp2 = []

 

  # alphabet sequence

alphabet = "abcdefghijklmnopqrstuvwxyz"

 

# Variable power

  power = 2 * * (length - 1 )

 

for i in range ( 0 , power):

 

# timeline

sub = " "

Shift =

x = 0

sub + = String [x]

x + = 1

for j in range (length - 1 ):

if Shift & amp; 1 :

sub + = ""

Shift = Shift"" 1

sub + = String [x]

  x + = 1  

temp1.append ( list ( map ( int , sub.split ())))

 

# Integer to string

for index in temp1: 

substring = ""

for j in index:

if j"  0 and j " = 26

  substring + = alphabet [j - 1 ]

if len (substring) = = len (index):

temp2.append (substring)

 

# lexicographic order sorting  

print ( * sorted (temp2), sep = "" )

 
Driver code

Number_to_String ( "191" )

Number_to_String ( "1991" )

Number_to_String ( "1532" )

Number_to_String ( "1191" )

Output:

 aia sa aiia sia aecb ocb aaia asa kia 

Python | Print all string combinations from given numbers Python functions: Questions

Python | Print all string combinations from given numbers String Variables: Questions

Shop

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

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

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