Python non-recursive full array

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.