list1 = [1, 2]
list2 = [3, 4]
list3 = [5, 6]
def fn(lists):
# 省略处理过程
...
res = fn([list1, list2, list3])
print(res)
# 最终结果为:
['1,3,5', '1,3,6', '1,4,5', '1,4,6', '2,3,5', '2,3,6', '2,4,5', '2,4,6']
def lists_combination(lists, code=''):
'''输入多个列表组成的列表, 输出其中每个列表所有元素可能的所有排列组合
code用于分隔每个元素'''
try:
import reduce
except:
from functools import reduce
def myfunc(list1, list2):
return [str(i)+code+str(j) for i in list1 for j in list2]
return reduce(myfunc, lists)
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |