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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!