This article describes how to implement full array output by using the python backtracking method, and analyzes in detail the definition of full sorting and the implementation skills of the backtracking method in the form of examples, for more information about how to implement full array output by using python backtracking, see the following example. 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.
From sys import stdout # code from http://www.bitsCN.com/def perm (li, start, end): if (start = end): for elem in li: stdout. write (elem) print ''else: for I in range (start, end): li [start], li [I] = li [I], li [start] perm (li, start + 1, end) li [I], li [start] = li [start], li [I] if _ name _ = '_ main _': li = ['A', 'B', 'C ', 'D '] perm (li, 0, len (li ))
I hope this article will help you with Python programming.