Answer the question
In order to leave comments, you need to log in
How to get all possible string "join" options from 4 or more arrays?
There are 4 arrays containing strings. You need to get a single array, which will contain all possible connections of strings from these arrays, despite the fact that the number of strings may not be the same in each of them. Using the example of arrays with one row:
Array 1 = ( 'a' );
Array 2 = ( 'б' );
Array 3 = ( 'в' );
Array 4 = ( 'г' );
result = (
'aб',
'ав',
'аг',
'бв',
'бг',
'вг',
'абвг'
)
аб, ав, аг, ба, бв, бг, ва, вб, вг, га, гб, гв, абвг
)
Answer the question
In order to leave comments, you need to log in
number of permutations - n factorial
i.e. count = len(a)*len(b)*len(c)*..*len(x)
algorithm - banal for over nested arrays
a = ['a1','a2','a3',]
b = ['b1',]
c = ['c1','c2',]
d = ['d1','d2','d3','d4',]
total = []
for i in range(0, len(a)):
for j in range(0, len(b)):
for k in range(0, len(c)):
for l in range(0, len(d)):
total.append(a[i]+b[j]+c[k]+d[l])
print(total)
print(len(total))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question