Python standard algorithm array arrangement method, python standard algorithm Array
This example describes how to use python standard algorithms to arrange arrays in full. The code is from a foreign website. Share it with you for your reference. The specific analysis is as follows:
M (m ≤ n) elements from n different elements are arranged in a certain order, which is called an arrangement of m elements from n different elements. When m = n, all data is arranged in full order.
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 resultdef MM (n): if (type (n )! = Int or n <2): return Mideng (list (range (1, n )))
Call method:
MM (6)
I hope this article will help you with Python programming.