I have a string like "12345" I need to make alp possible groups using the whole string. It should be something loke this. "12345" becomes [1, 2345], [12, 345]... [1234, 5], [12345]. In between these main headings I also need to consider pairs like [1,2, 34, 5], [12, 34, 5]. I figured these come by further splitting the [1] element. Like [1234,5] is also transformable as [12, 3,4,5]. In short using all the elements of a group to make 1 combination. get all such possible group combinations . My code:
final_list = {}
ex = ''
def get_all_comb(integer_string):
for ele in range(1, len(integer_string) + 1):
temp_1 = integer_string[:ele]
temp_2 = integer_string[ele:]
final_list[temp_1] = get_all_comb_helper(temp_2)
return final_list
def get_all_comb_helper(integer_string):
all_list = []
for ele in range(1, len(integer_string) + 1):
temp_1 = integer_string[:ele]
temp_2 = integer_string[ele:]
list_x = [temp_1,temp_2]
all_list.append(list_x)
return all_list
print(get_all_comb("12345")
Output:
{'i': [['2', '345'], ['23', '45'], ['234', '5'], ['2345', '']], 'i2': [['3', '45'], ['34', '5'], ['345', '']], 'i23': [['4', '5'], ['45', '']], 'i234': [['5', '']], 'i2345': []}
If you understood the question. Please help me. Time complexity is also an issue, went through itertools and found that accumulate does such a thing but only achieve the first line. Please suggest a method or a tool to do this o[eeatipn.
I tried itertools.Combinations and itertools.accumilate. I also tried a for loop where the iterator takes :index for one sub group amd index: for its corresponding remainder. I tried recursion on the remainder element to get the answer but it also has other possibilities in it and too random to clean up. Please help