Question: (In python) ff Problem 1: Write a function mytype(v) that performs the same action as type (), and can recog- nize integers, floats, strings, and
(In python)
ff
Problem 1: Write a function mytype(v) that performs the same action as type (), and can recog- nize integers, floats, strings, and lists. Do this by first using str(v), and then reading the string. Assume that lists can only contain numbers (not strings, other lists, etc...), and assume that strings can be anything that is not an integer, float or list. Note that an empty list () should also be recognized as a list. Test cases: mytype (10) and mytype (-10) should return "int"; mytype (-1.25) and mytype (10.0) should return "float"; mytype ([1, 2, 3]) and mytype([]) should return "list"; mytype ("abc") and mytype({1,2}) should return "string"; Problem 2: Write a function findpdfs (L) that takes as input a list L of filenames (such as "IMG2309.jpg, lecturel.pdf, homework.py"), and returns a list of the names of all PDF files, without extension ("lecturel). Assume that filenames may contain only letters and numbers. Test case: L = ["IMG2309.jpg", "lecture1.pdf", "homework.py", "homework2.pdf"] findpdfs(L) should return ("lecture1", "homework2")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
