python抄作业真香啊

import re 
def encrypt(x):
    if re.search('[0-9A-Fa-f]',x):
        return hex(int(bin(int(x,16))[2:].rjust(4,'0')[::-1],2))[2:].upper()
    else:
        return x
while True:
    try:
        a=list(input().replace(" ",""))
        a[::2]=sorted(a[::2])
        a[1::2]=sorted(a[1::2])
        res = ""
        for i in a:
            res+=encrypt(i)
        print(res)
    except:
        break