I was doing this exercise from here. I made a solution work but can't help feel it could have been done in fewer lines. I'm quite new to python so I'm not too sure of the little shortcuts.
def shift(S, n):
word = ''
for i in S:
if ord(i) == 32:
word += ' '
elif ord(i)+n > 90:
a = n-(90-ord(i))+64
word += chr(a)
else:
word +=chr(ord(i)+n)
return word
def TGS(x): # Total goodness of string
TGC = 0 # Total goodness of character
for i in x:
if ord(i) == 32:
continue
TGC += letterGoodness[ord(i)-65]
return TGC
A = input()
LOSS = [shift(A,n) for n in range (1,27)] # List of shifted strings
LOTG = [TGS(x) for x in LOSS]
a = LOTG.index(max(LOTG))
print(LOSS[a])
str.translate
. \$\endgroup\$