前提:主要是二维列表得出所有的排列组合(正序)
1、itertools(推荐)
import itertools
eg_list = [[1, 2], [3, 4]]
#property_item_list 二维列表
iter_list = itertools.product(*eg_list)
for iter in iter_list:
print(iter)
输出:
(1, 3)
(1, 4)
(2, 3)
(2, 4)
2、functools
eg_list = [[1, 2], [3, 4]]
from functools import reduce
fn = lambda x, code='|': reduce(lambda x, y: [str(i) + code + str(j) for i in x for j in y], x)
zuhe_list = fn(eg_list)
for zuhe in zuhe_list:
print(zuhe)
输出:
1|3
1|4
2|3
2|4