def test(s=""):
"""输入一个字符串,返回一个由这些字符组成的排列组合(递归思想)"""
if len(s) <= 1:
return [s]
else:
list1 = []
for i in range(len(s)):
for j in test(s[:i] + s[i + 1:]):
list1.append(s[i] + j)
return list1
if __name__ == "__main__":
s = 'abcd'
list1 = test(s)
print("排列组合数:%d" % len(list1))
print("排列组合数明细:%s" % str(list1))
import itertools
mylist = list(itertools.permutations(['A','B','C','D'],4)) # 全排列
print(mylist)
mylist1 = list(itertools.permutations(['A','B','C','D'],3)) # 4个里面选3个排列
print(mylist1)
#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'],4)) # 组合
print(mylist)
mylist1 = list(itertools.combinations(['A','B','C','D'],3)) # 4个里面选3个组合
print(mylist1)
#['A','B','C','D'],3) 4个取3个,无序
#M!/N!(M-N)!
import itertools
# product 可以重复的排序
# mylist1 = list(itertools.product("0123456789",repeat=4)) 参数表示可以重复的从前面的0到9里面取出4个数字来
# print(mylist1)
mylist=(["".join(x) for x in itertools.product("0123456789",repeat=4) ])
print(mylist)
print(len(mylist))
import itertools
# product 可以重复的排序
mylist=("".join(x) for x in itertools.product("0123456789",repeat=4))
print(next(mylist))
print(next(mylist))
print(next(mylist))
print(next(mylist))