Home:ALL Converter>Get every combination of the insertion of a character in a string

Get every combination of the insertion of a character in a string

Ask Time:2021-12-09T02:53:14         Author:neto

Json Formatter

For reference you can also see see this question: I am trying to finding every possible combination of adding a character to a string

Exactly as the other question I'm trying to get every single possible combination of the insertion of a character inside a string.

I don't understand how to implement the solution, specially how to get every combination of bits.

string = 'abc'

def generate_string(string):
    number_of_combinations = 2**(len(string)-1)
    str = ''
    configurations = []
    for i in range(number_of_combinations):
        #somehow get a true/false configuration of dashes
        #with abc i should have 8 possible configurations
        #i would append every configuration to configurations list
        
        for char in string:
            str = str + char
            #if the first char of configuration is true then add a '-', if false do nothing and so on for every char in the string

Can someone help me ?

Author:neto,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/70280295/get-every-combination-of-the-insertion-of-a-character-in-a-string
yy