Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python. Part I: String Sanitizer (20 points) Write a function sanitize) that takes one argument, st, which is a string that is supposed to contain
Python.
Part I: String Sanitizer (20 points) Write a function sanitize) that takes one argument, st, which is a string that is supposed to contain only uppercase letters, lowercase letters and digits (numbers in the form of a string) The function should analyze the string, then separate uppercase letters, lowercase letters and digits into three different result strings. In the end, the function puts these three strings into a single list, and returns the list. Note: Please make sure the order of the strings in your final list matches this order: string of uppercase letters, string of lowercase letters, string of digits] You should also make sure that when you construct the result strings, you should read st from left to right. Please check the examples below for more detail. If you encounter a character that's neither an uppercase letter, nor a lowercase letter nor a digit, your function should simply ignore that character and proceed through the remainder of the string Hint: You may find the following methods helpful. Please also consult the lecture slides. Python string.isupper method (https://www.tutorialspoint.com/python/string isupper.htm) Python string.islower ) method (https://www.tutorialspoint.com/python/string islower.htm) Python string.isdigit method (https://www.tutorialspoint.com/python/string isdigit.htm) Python string.isalpha ) method (https://www.tutorialspoint.com/python/string isalpha.htm) Examples: Return Value Function Call sanitize ('kBfmRG93& BvS') sanitize ('zs4*ia0QFer5' sanitize ('YIc!8pY14nM') sanitize (' 4utb8Z' sanitize (' 7P 8VC508@e2LTh') sanitize ('2YERJ3pKPZ9qU7nxR1'YERJKPZUR', pqnx', '23971' sanitize ('B4MP22EY4L6) sanitize (' 8um3bv2gtq3U6ww809f 'UWO',umbvgtqwf', '8323689' ] sanitize (' Z9NYRvfHx8SOB' ) sanitize ('IA8mH!R') BRBS', 'kfmv', ' 93' ['QF', 'zsiaer',4051 'YIYM, cpn', '814'1 'Z,utb '48' 1 PVCLT 'eh, '785082'] BMPEYL'42246' [ ZNYRHSP, 'vfx', 90' IAHR', 'm', '8' Note: The quotation marks displayed in the example return values are there to emphasize that the return values are strings. You should not add quotation marks to your return valuesStep 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