Python Backtracking Method for Analysis of output instances in full array arrangement and python instance analysis
This article describes how to implement full array output by using the python backtracking method. 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.bkjia.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.