Python regular method to achieve full array arrangement, python Array
This example describes how to arrange python arrays in a regular way. Share it with you for your reference. The specific analysis is as follows:
Full arrangement explanation: Any m (m ≤ n) elements from n different elements are arranged in a certain order, it is called an arrangement for retrieving m elements from n different elements. When m = n, all data is arranged in full order.
Def perm (l): if (len (l) <= 1): return [l] r = [] for I in range (len (l )): s = l [: I] + l [I + 1:] p = perm (s) for x in p: r. append (l [I: I + 1] + x) return r
Call method:
If _ name __= = '_ main _': "default param is list (1, 2, 3, 4, 5)" l = []; if (len (sys. argv) <= 1): "" input = ['% d' % (I) for I in xrange ()] "l = list, 3, 4, 5) else: # input param looks like "2, 3, 4, 5, 6", no legal checks here. input = str (sys. argv [1]) l = input. split (",") for I in xrange (len (l): l [I] = int (l [I]) print perm (l)
I hope this article will help you with Python programming.