how to print all combinations of a string in python

Solutions on MaxInterview for how to print all combinations of a string in python by the best coders in the world

showing results for - "how to print all combinations of a string in python"
Delanie
11 Mar 2016
1test_str = "abc"
2res = [test_str[i: j] for i in range(len(test_str)) 
3          for j in range(i + 1, len(test_str) + 1)]
4print(res)#['a', 'ab', 'abc', 'b', 'bc', 'c']
Eliott
13 Nov 2017
1import itertools
2 
3if __name__ == '__main__':
4 
5    nums = list("ABC")
6    permutations = list(itertools.permutations(nums))
7 
8    # Output: ['ABC', 'ACB', 'BAC', 'BCA', 'CAB', 'CBA']
9    print([''.join(permutation) for permutation in permutations])
queries leading to this page
combinations in python to stringpython all possible combinations of a stringcombination string pythonprint combinations pythonmake combination string pythonpython string combinationshow to get every 2 word combination of a string in pythonprint all possible combinations of stringall combinations of a string pythonprint all the possible combinations of a stringhow to print all possible combinations of a string in pythonhow to make string combinations in pythonpython get all combination of stringpython check for combinations of stringpython find all possible combinations of lettersget all possible combinations of characters given a string pythonstring combination in pythonfind the number of combinations of the string code in pythonhow to print all combinations of a string in pythonprint all combinations of a string pythongenerate all combinations of a string pythonpython all combinations of letterspython all combinations of two stringshow to make all possible combinations from strings in pythonall combinations of string pythonstring combinations in pythonpython print combinations of stringget all combinations of a string pythonpython print all possible combinations of lettersprint all combinations of a stringpython string all possible combinationshow to generate all possible combinations of characters of a string pythonall possible string combinations pythonall possible combinations of string pythoncombination in print pythonpython get all combinations of one stringreturn all combinations of char in list pythonhow to find combination in string pythonpython combinations of lettersnumber of combinations of string in python5 string combinations pythonprint combinations python listhow to get all the possible combinations of a string in pythonhow to print all combinations in pythonhow to find all possible combinations of a string in pythoncreate a combination of strings pythonprint all combinations of a string programall possible combinations of a string pythonprint all combinations of a given string in pythonhow to print all possible combinations of a stringhow to find combinations of string manually pythontrick to check all the possible combination of strings without using itertools in pythonpython find all combinations of a stringprint all the possible combinations of a string pythoncombinations of string in pythonpython all combinations of stringhow to check amount of combinations a string can have pythonfind all combinations of a string pythonprint all combinations pythonpython generate all combinations of stringshow to print all combinations of a string in python