Question: [Python] In the space below write a standalone function (not part of a class) called get_day_counts that does the following: 1) Takes in a single
[Python]
![[Python] In the space below write a standalone function (not part of](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f51d4757229_84666f51d46cf1ba.jpg)
In the space below write a standalone function (not part of a class) called get_day_counts that does the following: 1) Takes in a single parameter called lines with the lines from a file as a list of strings 2) Initializes day_dict to an empty dictionary 3) Uses a regular expression to find the day part of dates in the format MM/DD/YY or MM-DD-YY where MM is month, DD is the day, and YY is the year in the lines and uses day_dict to count the number of times each day appears. and 4) Returns a list of tuples (day count) sorted by count descending For example, get_day_counts(["02/04/20 12-30-19, 03/04/20, 08-20-30"]) returns [("04", 2), ("20", 1), ("30", 1)]. Run Load History Show CodeLens 3 1 import re 2 def get_day_counts(lines): # your code here 4 5 lines = ["02/04/20 12-30-19", "03/04/20", "08-20-30"] 6 print(get_day_counts(lines)) 7
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
