Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Retaining spaces in decoding process

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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()]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading