Advertisement
Olegos

Encode Palindrome

May 23rd, 2022
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1.  
  2. decoder = {'0': '0000', '1': '0001', '2': '0010', '3': '0011', '4': '0100', '5': '0101', '6': '0110', '7': '0111', '8': '1000', '9': '1001', 'A': '1010', 'B': '1011', 'C': '1100', 'D': '1101', 'E': '1110', 'F': '1111'}
  3.  
  4. double = []
  5. decode_inp = ([decoder[i] for i in '10836006F'])
  6. invert = [i[::-1] for i in decode_inp]
  7.  
  8. for i in sorted(set(decode_inp)):
  9.     if i in invert:
  10.         invert.remove(i[::-1])
  11.         double.append(i[::-1])
  12.  
  13. if double:
  14.     double = sorted(double, reverse=1)
  15.     double = double[1:len(double)] + [double[0]] + [i[::-1] for i in double[1:len(double)][::-1]]
  16.     print(''.join([{v:k for k,v in decoder.items()}[i] for i in double]))
  17. else:
  18.     print(*double)
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement