Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to print all combinations of a string in python

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

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

PREVIOUS NEXT
Code Example
Python :: minimum of two columns in pandas 
Python :: clearing canvas tkinter 
Python :: pandas replce none with nan 
Python :: how to round a number down in python 
Python :: python remove background 
Python :: find order of characters python 
Python :: replace transparent pixels python 
Python :: pandas subtract days from date 
Python :: new window selenium python 
Python :: pandas group by multiple columns and count 
Python :: python sort dict by key 
Python :: convert pdf folder to excell pandas 
Python :: python 3.9 features 
Python :: channel lock command in discord.py 
Python :: how to convert types of variablesin python 
Python :: python xml replace attribute value 
Python :: remove duplicates python 
Python :: transform categorical variables python 
Python :: add 2 set python 
Python :: pygame music player 
Python :: max pooling tf keras 
Python :: how to practise python 
Python :: python make file path os 
Python :: search google images python 
Python :: python dict print keys 
Python :: create an empty dataframe 
Python :: datetime.datetime.fromtimestamp() 
Python :: how to install from url in python 
Python :: tf dropout 
Python :: ordered dictionary python 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =