Remove Leading and Trailing Special Characters from Text
Beginner Mode

Start your terminal to use beginner mode.

Scenario

A text file contains strings with unwanted leading and trailing characters that need to be cleaned. The characters vary across different strings in the dataset.

Task

Write a Python script at /home/interview/clean_data.py that reads /home/interview/raw_data.txt, removes all leading and trailing special characters (*, #, -, _, !, @) and whitespace from each line, and writes the cleaned strings to /home/interview/cleaned_data.txt.

Example

Before (raw_data.txt):

***Hello World***
###Python Programming
  Data Science  
___Machine Learning___

After (cleaned_data.txt):

Hello World
Python Programming
Data Science
Machine Learning

Terminal requires a larger screen

Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.

Linux Terminal Environment

Write and execute your solution in the terminal below.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →