Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions