# Write a function that reads a todo.csv file. # The todo.csv file contains date, time, and activity # formatted as, for example, # date,time,thingstodo # 31oct,8am,eat # 31oct,9am,relax # 31oct,10am,meet advisor # 31oct,11am,read # 31oct,12pm,eat # 31oct,1pm,get ready for cs1111 # 31oct,2pm,cs1111 # 31oct,3:30pm,some other class # 31oct,5pm,do homework # 31oct,6pm,eat # 31oct,7pm,practice writing program # where the first line is a header line # The function then counts the numbers of activities that will happen # in AM and PM, and return a dictionary containing the numbers of # AM activities and PM activities. # For example, {'number_AM_todo': 4, 'number_PM_todo': 7} def read_file(): # open a file # read the file # iterate the lines # for each line, split, get each piece # look for the piece we are interested in # use it somehow infile = open('todo.csv', 'r') # infile.read() get string of entire file # infile.readlines() get list of lines todo_dict = {'number_AM':0, 'number_PM':0} list_of_lines = infile.readlines() # list_of_lines = infile.read().split('\n') # list of lines for line in list_of_lines: columns = line.split(',') if 'am' in columns[1] or 'AM' in columns[1]: todo_dict['number_AM'] += 1 elif 'pm' in columns[1] or 'PM' in columns[1]: todo_dict['number_PM'] += 1 infile.close() return todo_dict print(read_file())