PythonPython
2025-10-08 17:14阅读:24评论:0
使用Python轻松实现笛卡尔积组合
输入
1
2
3
4
5
6
7
8
import itertools list1 = ['A','B','C']list2 = ['1','2','3']list3 = ['红色','绿色','白色']for e in itertools.product(list1, list2, list3): print(e) _PROTECTED0__
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
('A', '1', '红色')('A', '1', '绿色')('A', '1', '白色')('A', '2', '红色')('A', '2', '绿色')('A', '2', '白色')('A', '3', '红色')('A', '3', '绿色')('A', '3', '白色')('B', '1', '红色')('B', '1', '绿色')('B', '1', '白色')('B', '2', '红色')('B', '2', '绿色')('B', '2', '白色')('B', '3', '红色')('B', '3', '绿色')('B', '3', '白色')('C', '1', '红色')('C', '1', '绿色')('C', '1', '白色')('C', '2', '红色')('C', '2', '绿色')('C', '2', '白色')('C', '3', '红色')('C', '3', '绿色')('C', '3', '白色')