Question
CS 103 INTRO TO COMPUTER SCIENCE IN PYTHON. PROBLEM: Write the function improveFilename that takes a string fn and transforms the string into a legal
CS 103 INTRO TO COMPUTER SCIENCE IN PYTHON.
PROBLEM: Write the function improveFilename that takes a string fn and transforms the string into a legal identifier with only ASCII letters, decimal digits, and underscores.
In particular, replace all whitespace characters by underscores, remove other illegal characters (such as parentheses), and if the string begins with a digit, add a leading underscore in front of this digit (since identifiers cannot begin with a digit). You can use the string module's string constant string.whitespace to identify whitespace characters (such as tabs), string.ascii_letters to identify ASCII letters, and string.digits to identify digits. The string module's replace function is banned. I am looking for a standard iterative solution here.
The following syntax is banned: printing, the replace function, use of the Numpy module, and recursion.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started