+ 1
Code Coach Python Symbols
Is there a simpler way of removing all symbols from a string with regular expressions? import re input = input() output = "" pattern = re.compile(r"\w|\s") for i in input: if pattern.findall(i): output += i print(output)
10 odpowiedzi
+ 6
yes, it can be done in one line if you dont count the import line. check out my code buts in my profile.
import re
#one liner is shorter
print("".join(re.findall(r"[A-Za-z\d\s]+", input())))
+ 3
Thanks! I didn’t quite get it working that way but it led me to this:
import re
input = input()
output = re.sub(r"[^\w\s]", "", input)
print(output)
+ 3
Here without regex
print(''.join(e for e in input() if e.isalnum() or e==' '))
+ 1
Here's how I did mine.
import re
print(''.join(re.findall(r'\w|\s', input())))
+ 1
def clean_string(string):
new_string = ""
for i in string:
if i.isalpha() or i.isspace() or i.isdigit() == True:
new_string += i
return new_string
string = input()
print(clean_string(string))
+ 1
My solution:
y = "qwertzuiopasdfghjklyxcvbnm QWERTZUIOPASDFGHJKLYXCVBNM1234567890"
x = input()
output = ""
for i in x:
if i in y:
output += i
else:
continue
print(output)
0
Yes. You can change it to:
pattern = re.compile(r"\W|\S") #anything that isn't a letter, underscore, or space
Then, you should use re.sub:
output = re.sub("", pattern) #removes anything that is a symbol
0
def decode(string):
return "".join(
c for c in string
if c.isalpha() or c.isdigit () or c== " "
)
print(decode(input())) try it i use is alpha merthod
0
import string
symbols = string.punctuation
scrambled = input()
table = str.maketrans("", "", symbols)
stripped = scrambled.translate(table)
print(stripped)
0
My solution with python
mess = input()
message =""
alphabet=" 1234567890abcdefghijklmnopqrstuvwxyz"
for i in mess :
for j in alphabet :
if i == j or i == j.upper ():
message += i
print(message)