Horje
python print combinations of string Code Example
python print combinations of string
test_str = "abc"
res = [test_str[i: j] for i in range(len(test_str)) 
          for j in range(i + 1, len(test_str) + 1)]
print(res)#['a', 'ab', 'abc', 'b', 'bc', 'c']
python print combinations of string
import itertools
 
if __name__ == '__main__':
 
    nums = list("ABC")
    permutations = list(itertools.permutations(nums))
 
    # Output: ['ABC', 'ACB', 'BAC', 'BCA', 'CAB', 'CBA']
    print([''.join(permutation) for permutation in permutations])




Python

Related
read all text file python Code Example read all text file python Code Example
how to use regex in a list Code Example how to use regex in a list Code Example
python sorting array without inbuilt sort Code Example python sorting array without inbuilt sort Code Example
python sorted dictionary multiple keys Code Example python sorted dictionary multiple keys Code Example
arch linux python 3.7 Code Example arch linux python 3.7 Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8