So this code already works, but I would like to shorten it using list comprehension. Would it be better if it was in 1 line, or many? (I do know that readability is more important than short code, but I would like to master list comprehension, ternary operators, and conditional expressions). Oh yes, if there is ANYTHING I can do to make my code better, more efficient, more readable and shorter, I would LOVE to know!
#Caesar Cipher, only lowercase and spaces
listString = [x for x in input('What would you like to encode? ')]
change = int(input('How much would you like to shift? '))
change %= 26
def encode(listString,change):
encoded = []
for c in listString:
if ord(c) + change > 122:
encoded.append(chr(ord(c) + (change - 26)))
continue
encoded = [" " if x == chr(32 + change) else x for x in encoded]
encoded.append(chr(ord(c) + change))
return "".join(encoded)
print(encode(listString,change))