Python 官方文档:入门教程 => 点击学习
排列 例如: 输入为 [‘1’,’2’,’3’]和3 输出为 [‘111’,’112’,’113’,’121’,’122’,’123’,’131’,’132’,’133’,’211’,’212’,’213’,’221’,’
例如:
输入为
[‘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’]
from itertools import product
l = [1, 2, 3]
print list(product(l, l))
print list(product(l, repeat=3))
例如:
输入为
[1, 2, 3]和2
输出为
[1, 2], [1, 3], [2, 3] 不考虑顺序
from itertools import combinations
l = [1, 2, 3, 4, 5]
print list(combinations(l, 3))
--结束END--
本文标题: python list的排列组合
本文链接: https://www.lsjlt.com/news/190276.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0