s = ‘2kd4-1124*2|^2sdAmZ%fkMcv‘ def fun(s): li = [] li2 = [] tu = () for i in s: li.append(i) print(‘排序前:‘,end=‘‘) print(li) n = len(li) for i in range(n-1): for j in range(n-1-i): if li[j]<li[j+1]: li[j],li[j+1] = li[j+1],li[j] if n%2==0: for i in range(n//2): li2.append(‘({},{})‘.format(li[i],li[n-1-i])) else: for i in range(n//2): li2.append(‘({},{})‘.format(li[i], li[n-1-i])) li2.append(‘({})‘.format(li[n//2])) print(‘排序后:‘,end=‘‘) print(li) return tuple(li2) tu = fun(s) print(‘新格式:‘,end=‘‘) print(tu)
时间: 2024-10-12 23:32:58