Question: Rewrite the following code as one single function, create_time_list(filename). def extract time (string): Converts string to time tuple Params string: str Returns tuple containing 3
Rewrite the following code as one single function, create_time_list(filename).

def extract time (string): "Converts string to time tuple Params string: str Returns tuple containing 3 member (hours, minues, am/pm) TT TT TT 1s = string.strip().split() # raise error if string is not in proper format if len(13) != 3 or (not ls[0].isnumeric()) or (not ls[1].isnumeric()) or (ls [2] != 'AM' and ls [2] != 'PM'): raise ImproperTimeError("Time is not in proper format.") time = (int(ls[0]), int(1s[1]), 1s[2]) # raise error if value of hour and minute are not in range if time[0] 12 or time[1] 59: raise ImproperTimeError("Time is not is proper format.") return time def create_time_list(filename) : "Reads file for time and converts each line to time tuple Params ---- filename: string name of the file to be processed Returns list of tuples TTTTTT with open(filename, 'r') as file: lines = file.readlines () # raise error if file is empty if len (lines)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
