题目
已知两个列表
lst_1 = [1, 2, 3, 4]
lst_2 = ['a', 'b', 'c', 'd']
将两个列表交叉相乘,生成如下的矩阵
[['1a', '2a', '3a', '4a'],
['1b', '2b', '3b', '4b'],
['1c', '2c', '3c', '4c'],
['1d', '2d', '3d', '4d']]
import pprint
lst_1 = [1, 2, 3, 4]
lst_2 = ['a', 'b', 'c', 'd']
lst_3 = []
for l2 in lst_2:
tmp = []
for l1 in lst_1:
tmp.append(str(l1)+l2)
lst_3.append(tmp)
#pprint和print功能其实是一样,就是打印的格式看起来不一样而已
pprint.pprint(lst_3)
print(lst_3)