I need to write a program that will take the encoded message, flip it around, remove any characters that are not a letter or a space, and output the hidden message.
Sample input:
d89%l++5r19o7W *o=l645le9H
Expected output:
Hello World
My output:
HelloWorld
If I use a white space as separator, it returns
H e l l o w o r l d
My code:
decode = [ch for ch in input() if ch.isalpha()]
print("".join(decode[::-1]))
>Solution :
The space character is not an alphanumeric character.
In your original code, use:
decode = [ch for ch in input() if ch.isalpha() or ch == ' ']
instead.
If you want to retain other types of whitespace besides the space character (e.g. tabs, newlines), use:
decode = [ch for ch in input() if ch.isalpha() or ch.isspace()]