I wanted to list all the associative operation possible for an n-elements group. For example, when n=3, I want it to print:
a*(a*a) = (a*a)*a
a*(a*b) = (a*a)*b
a*(a*c) = (a*a)*c
... 24 more lines
Now, my best attempt to produce these is the following python3 code.
import itertools as it
def permutation_func(str_, rep):
chars = list(str_)
results = []
for tuple_ in it.product(chars, repeat = rep):
i = ''.join(tuple_)
results.append(i)
return results
my_list = permutation_func('abc', 3)
for i in my_list:
print(i, " = ", i)
However, the output I am getting is:
aaa = aaa
aab = aab
aac = aac
... and 24 more lines
I think I am on the right track. But I cannot figure it out how to transform aaa = aaa to a*(a*a) = (a*a)*a which is basically I need to insert the * sign and the parentheses multiple times inside the text.
I have tried googling and I found that I need regular expressions to do this. However, I never used regular expression. So I am looking for an alternative that does not use regular expression. I don't even know whether it is possible without regular expression. If it is not, let me know please.