* * 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)