python print combinations of string

Solutions on MaxInterview for python print combinations of string by the best coders in the world

showing results for - "python print combinations of string"
Emilio
08 Jan 2018
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']
Hanna
18 Nov 2018
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])