import itertools mylist=list(itertools.permutations(['A','B','C','D'],4))#全排列 print(mylist) print(len(mylist)) #itertools.permutations([1,2,3,4],2)排列,4个数的列表,取出3个数,不同的顺序算, #5!=1*2*3*4*5 #0!=1 #M个选N个 M!/(M-N)! #4 1 4!/3!=4 #4 2 4!/2!=3*4=12 #4 3 4!/1!=24
import itertools mylist=list(itertools.combinations(['A','B','C','D'],3)) print(mylist) print(len(mylist)) #['A','B','C','D'],3) 4个取3个,无序 #M!/N!(M-N)!