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']
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])