I want to write a program that gives 2 strings(char type) and combine them in different ways.
for example if 2 strings are "abc" and "mn" the program should print :
abcmn abmnc amnbc mnabc mabcn mannbc mabnc ambnc ambcn abmcn
as you see they should be in ordered form in each string. I mean that for example "c" couldn't be before "a" or "n" couldn't be before "m"
what can I do?
'm' can be inserted in four positions: 1a2b3c4
For each case, 'n' can be inserted after 'm' or any charater that will be after the 'm'.
Thus, when 'm' is in position 1, 'n' has 4 possibilities.
When 'm' is in position 2, 'n' has 3 possibilities.
>>> from itertools import permutations
>>> def all_perm(*args):
... s = ''.join(sorted(args))
... for cbn in permutations(s):
... yield ''.join(cbn)
>>> for word in all_perm('abc', 'mn'):
... print word,