python 从m个数中取n个做不重复排列

需要用到itertools.combinations方法
m也可以是list,tuple,dict等对象

from itertools import combinations
m =['1', '2', '3', '4', '5', '6', '7']
c = 0
n=6
for i in list(combinations(m,n)):
print(i)
c=c+1
print(c)
posted @ 2022-06-08 00:15  遇事不决,量子力学  阅读(315)  评论(0编辑  收藏  举报