Python face question (i)

Source: Internet
Author: User

* * At the company's forum in the evening to see an interview problem, the title is as follows: randomly given a string and characters, require rearrangement, such as: ' Abde ', ' C '. Rearrange to become ' ABCDE '

* * see that they give many of the answers are two-way rearrangement, since it is the processing of the character class, of course, the ASCII code table corresponding to the number of processing, so here is a simple way to write out, the code is as follows:

defSt (S1,S2):#Sort FirstL =sorted (S1)#and then traverse     forIinchL:ifi = =S2:ind=L.index (i) L.insert (Ind, S2)returnLelifI < s2 andL[l.index (i) + 1] >S2:l.insert (L.index (i)+ 1, S2)returnLelifi > S2 andL[l.index (i)-1] <S2:l.insert (L.index (i)-1, S2)returnLelifL[-1] <S2:l.insert (Len (l), S2)returnLelifL[0] >s2:l.insert (0, S2)returnL

* * Test steps:

s1='ahijklvwx's2='d'print st (S1,S2)

* * Test results: Do not know if there is no bug (numbers, uppercase letters, special characters Nonalphanumeric tried), and finally converted to a string, the code is not written out

['a','D','h','I','J','k','L','v','W','x']

Generated by Haroopad

Python face question (i)

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.