我有这个清单:
list = [['a','b'],
['1', '2', '3'],
['r', 's', 't','u']]
我想将子列表中所有元素的所有唯一组合都包含在如下列表中:
['a1r','a1s','a1t','a1u','a2r','a2s','a2t','a2u','a3r','a3s','a3t','a3u',
'b1r','b1s','b1t','b1u','b2r','b2s','b2t','b2u','b3r','b3s','b3t','b3u']
我曾尝试编写这段代码,它只给出了前四种组合:
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)
我从代码中得到的输出是:
['a1r', 'a1s', 'a1t', 'a1u']
我应该做哪些改变?