Data sanitization

Problem Statement

The company ABC is into social media analytics. It wants to analyse the feed from twitter. For that it needs to clean the data.

Write a function that keeps only the alphabets and spaces, and removes all other characters from the given string.

Input

The first line of input is a string: text, representing the data from social media feed.

Output

Print the cleaned string.

As is

The boilerplate code is already there to read the inputs from user, in the main() function, and to print the value returned by the cleanString() function. Do not edit this code.

To do ✍

cleanString() has one parameter: text. Write code inside the function body to remove the characters other than alphabets and spaces, and return the cleaned text.

Example 1

Test input

This is 0 sample, paragr..aph.

Test output

This is  sample paragraph

Explanation

Since we need to keep only the alphabets, and whitespace characters, rest all characters are replaced with an empty string.

Useful References

Python Program

import re

# Complete the following function
def cleanString(text):




# Boilerplate code - Do not edit the following
def main():
    text = input()
    print(cleanString(text))

if __name__ == "__main__":
    main()

Input and Outputs 1

Apple is red. *#fruit 41 supply
Apple is red fruit  supply

Input and Outputs 2

hell23o worl01
hello worl

Input and Outputs 3

This is 0 sample, paragr..aph.
This is  sample paragraph
import re

# Complete the following function
def cleanString(text):
    cleaned_text = re.sub(r'[^a-zA-Z\s]', '', text)
    return cleaned_text

# Boilerplate code - Do not edit the following
def main():
    text = input()
    print(cleanString(text))

if __name__ == "__main__":
    main()
show answer
main.py
⏵︎ Run Tests
Reset
Download
×
Code copied to clipboard successfully 👍