本文实例讲述了python列表list排列组合操作。分享给大家供大家参考,具体如下:
排列
例如:
输入为
['1','2','3']和3
输出为
['111','112','113','121','122','123','131','132','133','211','212','213','221','222','223','231','232','233','311','312','313','321','322','323','331','332','333']
实现代码:
# -*- coding:utf-8 -*-
#! pyhton2
from itertools import product
l = [1, 2, 3]
print list(product(l, l))
print list(product(l, repeat=3))
上述代码运行输出:
[(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)]
[(1, 1, 1), (1, 1, 2), (1, 1, 3), (1, 2, 1), (1, 2, 2), (1, 2, 3), (1, 3,