Python | Print all string combination from given numbers Last Updated : 16 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an integer N as input, the task is to print the all the string combination from it in lexicographical order. 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 Approach: Get the String and find all its combination list in the given order. Find the list whose integers lies in the range of 0 to 25. Convert the integers to the alphabets. Sort it in lexicographical order. Python3 1== # Python program to print all string # combination from given numbers # Function to find the combination def Number_to_String(String): # length of string length = len(String) # temporary lists temp1 =[] temp2 =[] # alphabets Sequence alphabet ="abcdefghijklmnopqrstuvwxyz" # Power variable power = 2**(length-1) for i in range(0, power): # temporary String sub = "" Shift = i x = 0 sub += String[x] x += 1 for j in range(length - 1): if Shift&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) # lexicographical 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 Comment More infoAdvertise with us Next Article itertools.combinations() Module in Python to Print All Possible Combinations V VISHAL_PERIYASAMY_R Follow Improve Article Tags : Python Practice Tags : python Similar Reads itertools.combinations() Module in Python to Print All Possible Combinations When given an array of size n, one common problem is generating all possible combinations of r elements.For example:Input: arr[] = [1, 2, 3, 4], r = 2Output: [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]Although, there can be a recursive solution for this problem, but in this article we'll focus 2 min read Permutation and Combination in Python Python provides built-in methods to work with permutations and combinations using the itertools module. These are helpful in problems involving arrangement (order matters) and selection (order doesnât matter) of elements.Let's explore them one by one:PermutationA permutation is an arrangement of ele 2 min read Python | Size Range Combinations in list The problem of finding the combinations of list elements of specific size has been discussed. But sometimes, we require more and we wish to have all the combinations of elements of all sizes in range between i and j. Letâs discuss certain ways in which this function can be performed. Method #1 : Usi 4 min read Combinations in Python without using itertools Itertools in Python is a module that produces complex iterators with the help of methods that work on iterators. This module works as a fast, memory-efficient tool that is used either by itself or in combination to form iterator algebra. Printing Combinations Using itertoolsUsing Itertools we can di 3 min read Get a list as input from user in Python We often encounter a situation when we need to take a number/string as input from the user. In this article, we will see how to take a list as input from the user using Python.Get list as input Using split() MethodThe input() function can be combined with split() to accept multiple elements in a sin 3 min read Python Program to print all permutations of a given string A permutation also called an "arrangement number" or "order," is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with S itself. A string of length n has n! permutation. Source: Mathword(http://mathworld.wolfram.com/Permutation.html) Below are the permutations of 2 min read Like