I have this list:
list = [['a','b'],
['1', '2', '3'],
['r', 's', 't','u']]
I want to have all the unique combinations of all elements from the sub-list in a list like bellow:
['a1r','a1s','a1t','a1u','a2r','a2s','a2t','a2u','a3r','a3s','a3t','a3u',
'b1r','b1s','b1t','b1u','b2r','b2s','b2t','b2u','b3r','b3s','b3t','b3u']
I have tried writing this code, which only gives me first four combinations:
list = [['a','b'],
['1', '2', '3'],
['r', 's', 't','u']]
i = j = k = 0
x = y = z = ''
str = ''
final_list = []
while i <= 1:
x = list[0][i]
i += 1
while j <= 2:
y = list[1][j]
j += 1
while k <= 3:
z = list[2][k]
k += 1
str = x + y + z
final_list.append(str)
print(final_list)
The output I get from my code is:
['a1r', 'a1s', 'a1t', 'a1u']
What changes should I make?