例如,拥有字符串:
abcdefghijklmnopqrstuvwxyz
Run Code Online (Sandbox Code Playgroud)
应该导致这样的事情:
badcfehgjilknmporqtsvuxwzy
Run Code Online (Sandbox Code Playgroud)
我怎么去呢?
我想到了一些效率不高的东西,例如:
s = str(range(ord('a'), ord('z') + 1))
new_s = ''
for i in xrange(len(s)):
if i != 0 and i % 2 == 0:
new_s += '_' + s[i]
else:
new_s += s[i]
# Now it should result in a string such as 'ab_cd_ef_...wx_yz'
l = new_s.split('_')
for i in xrange(len(l)):
l[i] = l[i][::-1]
result = str(l)
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法?某种方式更有效或更一般,所以我也可以更轻松地用3个字母去做?
我有32位程序集的问题,在linux上用NASM组装它.这是我对插入排序的实现
myInsertionSort:
push ebp
mov ebp, esp
push ebx
push esi
push edi
mov ecx, [ebp+12] ;put len in ecx, our loop variable
mov eax, 1 ; size of one spot in array, one byte
mov ebx, 0
mov esi, [ebp+8] ; the array
loop loop_1
loop_1:
cmp eax, ecx ; if we're done
jge done_1 ; then done with loop
push ecx ; we save len, because loop command decrements ecx
mov ecx, [esi+eax] ; ecx now array[i]
mov …Run Code Online (Sandbox Code Playgroud)