Just started to learn python, according to Liaoche's web site, currently see the function of this Section. In conjunction with array manipulation, a non-recursive, fully arranged generation is Written. The principle is the insertion method, that is, in an existing arrangement of N elements, followed by the elements, sequentially in front, in, after each position inserted, generated n+1 a new full arrangement. Because Python cuts arrays or strings, and merges are convenient, the program saves a lot of code.
1 defgetarrayinsertchartostr (str,char):2arr =[]3S_len =Len (STR)4index =05 whileIndex <=s_len:6 #Split String7Arr.append (str[:index]+char+Str[index:s_len])8index = index + 19 returnarrTen one defGetarrayinsertchartoarray (array,char): aindex =0 -Re_array = [] - whileIndex <Len (array): theRe_array = Re_array +getarrayinsertchartostr (array[index],char) -index = index + 1 - returnRe_array - + defgetpermutation (STR): -Resultarr =[str[0]] + forIteminchStr[1:]: aResultarr =Getarrayinsertchartoarray (resultarr,item) at returnResultarr - - - Print(getpermutation ('ABC'))
Python non-recursive full array