The Spy Life code coach [Different Approach] [python] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

The Spy Life code coach [Different Approach] [python]

code = input()[::-1] encode = "" for x in code: if x.isalpha() == True or x.isspace() == True: encode += x print(encode) PS: Suggestions are welcome 🙂

30th Oct 2022, 11:16 AM
Shaleen Chowdhary
Shaleen Chowdhary - avatar
3 Answers
+ 10
Aquarius , the code is well done. not an important change, but just for information: #if x.isalpha() == True or x.isspace() == True: # <<< instead of using this if x.isalpha() or x.isspace(): # <<< we can also use this
30th Oct 2022, 3:03 PM
Lothar
Lothar - avatar
+ 3
Some other possible approaches to remove characters from a string: - use a list comprehension with a condition - use the filter() function
30th Oct 2022, 12:09 PM
Tibor Santa
Tibor Santa - avatar
0
Lothar , thanks this will make the code more organised..
30th Oct 2022, 6:58 PM
Shaleen Chowdhary
Shaleen Chowdhary - avatar