join sorted list input split upper replace key lambda ord reverse True

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
n = "".join(sorted(list(input().split('.')[0].upper().replace(' ','')),key = lambda x: ord(x),reverse = True))
ans = ''
ans2 = ''
p = 0
while n != '':
count = n.count(n[0])
if count%2 == 0:
ans += n[0]*(count//2)
ans2 = n[0]*(count//2)+ans2
else:
p += 1
t = n[0]*count
if p == 2:
print("NO")
break
n = n.replace(n[0], '')
else:
print(ans+t+ans2)