Example: A B C D 4 elements result: WITH TWO ELEMENTS AB B.C AD BC BD CD
WITH THREE ELEMENTS ABC ABD ACD BCD
Example: A B C D 4 elements result: WITH TWO ELEMENTS AB B.C AD BC BD CD
WITH THREE ELEMENTS ABC ABD ACD BCD
Here it is:
from itertools import permutations
import re
caracteres = ['A', 'B', 'C', 'D']
for i in permutations(caracteres,2): # 2 elementos
i = re.sub(r'\W',"",str(i)) # Retirando outros caracteres que não sejam letras
print(i)
print()
for i in permutations(caracteres,3): # 3 Elementos
i = re.sub(r'\W',"",str(i))
print(i)
print()
for i in permutations(caracteres,4): # 4 Elementos
i = re.sub(r'\W',"",str(i))
print(i)