Wednesday, October 4, 2017

Only Alphabets and Space

Given a String S, remove all the special characters and numbers from S and print.

Input Format:
The first line contains the string S

Output Format:
The first line contains the string with only alphabets and spaces.

Boundary Conditions: 1 < Length of S < 1000

Example Input/Output 1:
Input:
Hello #$ World!
Output:
Hello World

Solution 1:
import re
print(''.join(re.findall('[A-Za-z]+|\s',input())))

Solution 2:
s=input()
for i in s:
    if i.isalpha() or i==' ':
       print(i,end='')
Share: