The python standard algorithm implements the full array arrangement method
- 2020-04-02 14:41:16
- OfStack
This article describes the python standard algorithm to achieve the full array array method, code from foreign websites. Share with you for your reference. Specific analysis is as follows:
Taking m (m Or less n) elements from n different elements and arranging them in a certain order is called taking m elements from n different elements. All permutations when m is equal to n are called all permutations.
def Mideng(li):
if(type(li)!=list):
return
if(len(li)==1):
return [li]
result=[]
for i in range(0,len(li[:])):
bak=li[:]
head=bak.pop(i) #head of the recursive-produced value
for j in Mideng(bak):
j.insert(0,head)
result.append(j)
return result
def MM(n):
if(type(n)!=int or n<2):
return
return Mideng(list(range(1,n)))
Call method:
MM(6)
I hope this article has helped you with your Python programming.