How can I solve the Symbols problem in Code Coach using Python? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

How can I solve the Symbols problem in Code Coach using Python?

The task is to get a string input consisting of words and numbers with random symbols in between and then output the string without the symbols. For example: Input: Al@

amp;+$+#ph$a B@$&e#&ta 12@#&$345 Output: Alpha Beta 12345 I am using Python's re module for this.

25th May 2020, 10:00 AM
Ayush Tripathi
Ayush Tripathi - avatar
7 Antworten
+ 4
It's also possible to do it with a simple for loop or with a comprehension.
25th May 2020, 10:21 AM
Lothar
Lothar - avatar
+ 2
regex u can use re.sub and remove the unwanted char
25th May 2020, 10:06 AM
durian
durian - avatar
+ 2
input = "Al@
amp;+$+#ph$a B@$&e#&ta 12@#&$345" output = re.sub("[^\w\s]*", "", inp)
25th May 2020, 10:50 AM
durian
durian - avatar
25th May 2020, 10:43 AM
Lerninn
0
­ŁÉŐ­ŁÉó­ŁÉó­ŁÉŤ­ŁÉĘ ­ŁÉć­ŁÉí­ŁÉÜ­ŁÉ▓­ŁÉÜ­ŁÉą i provided him the regex split pattern. If you are saying that, let him try his attempt. What he'll do? He can no further edit his code instead of just changing patterns. he mentioned to use re module.
25th May 2020, 11:07 AM
Lerninn
0
print(''.join(e for e in input() if e.isalnum() or e==' '))
11th Jun 2021, 11:29 AM
Naveen Surya
Naveen Surya - avatar