I have this string: "AAABBB"
and this string "--"
.
How can i find in recursion, all of the permutations of the merged string "--AAABBB"
?
But "AAABBB"
must stay at her order. For example:
--AAABBB
-A-AABBB
-AA-ABBB
.
..
.
.AAABBB--
I have this string: "AAABBB"
and this string "--"
.
How can i find in recursion, all of the permutations of the merged string "--AAABBB"
?
But "AAABBB"
must stay at her order. For example:
--AAABBB
-A-AABBB
-AA-ABBB
.
..
.
.AAABBB--
Here's a recursive generator implementation:
def comb(first_str, second_str):if not first_str:yield second_strreturnif not second_str:yield first_strreturnfor result in comb(first_str[1:], second_str):yield first_str[0] + resultfor result in comb(first_str, second_str[1:]):yield second_str[0] + result
Output with your strings:
>>> for result in comb("--", "AAABBB"):print(result)--AAABBB
-A-AABBB
-AA-ABBB
-AAA-BBB
-AAAB-BB
-AAABB-B
-AAABBB-
A--AABBB
A-A-ABBB
A-AA-BBB
A-AAB-BB
A-AABB-B
A-AABBB-
AA--ABBB
AA-A-BBB
AA-AB-BB
AA-ABB-B
AA-ABBB-
AAA--BBB
AAA-B-BB
AAA-BB-B
AAA-BBB-
AAAB--BB
AAAB-B-B
AAAB-BB-
AAABB--B
AAABB-B-
AAABBB--