+ 1

How to remove alphabets characters from the input String?

Input : @1456hello13#%+?!/:'*" Output : @145613#%+?!/:'*"

8th May 2020, 5:51 AM
Baljinder Singh
Baljinder Singh - avatar
5 ответов
+ 2
result = "".join(list(filter(lambda x: not x.isalpha(), input()))) print(result)
8th May 2020, 6:16 AM
Ipang
+ 1
Javascript code is wrong
8th May 2020, 6:13 AM
Baljinder Singh
Baljinder Singh - avatar
+ 1
A bit late, but anyway my try with a pure list comprehension: inp = "@1456hello13#%+?!/:'*" #Output : @145613#%+?!/:'*" # if you need to get the result as data res = ''.join([i for i in inp if not i.isalpha()]) print(res) # if you only need to print result print(''.join([i for i in inp if not i.isalpha()]))
8th May 2020, 9:26 AM
Lothar
Lothar - avatar
0
In javascript : const string = "@1456hello13#%+?!:'*"; const withoutChar = string.replace(/[a-zA-Z]/g, ''); console.log(withoutChar); In python is almost same : import re re.sub('[a-zA-Z]', '', string); print(string);
8th May 2020, 5:59 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
0
Black Cap🇮🇳 Hey, lol. I forgot to include that tiny 'g' after /[a-zA-Z]/. Please test it again :))
8th May 2020, 8:05 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar