fork download
  1. def list_formula(a, b): # 把要對 a, b 做的各種運算都放在這邊
  2. result = a * b
  3. return result
  4.  
  5.  
  6. def main():
  7. list_a = [2, 3, 4, 5, 6, 7] # 即使 list_a, list_b 的長度不同也能相乘
  8. list_b = [5, 6, 7, 8, 9]
  9.  
  10. len_of_list_a = len(list_a) # list_a 矩陣長度
  11.  
  12. # 一口氣把結果放到 list_c
  13. list_c = [map(list_formula, list_a, [x] * len_of_list_a) for x in list_b]
  14.  
  15. for row in list_c: # 一行行的印出處理後的矩陣
  16. print(*row)
  17.  
  18. if __name__ == '__main__':
  19. main()
  20.  
Success #stdin #stdout 0.03s 9340KB
stdin
Standard input is empty
stdout
10 15 20 25 30 35
12 18 24 30 36 42
14 21 28 35 42 49
16 24 32 40 48 56
18 27 36 45 54 63