Question: python 3 that't the code I wrote everything is working I just have to fix the for loop to print the correct activity count: def
python 3
that't the code I wrote everything is working I just have to fix the for loop to print the correct activity count:
def clean_data(activity): result = [] for a in activity: tokens = [x.lower().strip() for x in a.split()[1:]] result = result + tokens return result def count_activites(activity, activity_list): return activity_list.count(activity) def unique_activities(activity_list): return list(set(activity_list)) # copy your physical activity data below: physical_activity_data = [ 'eqc244, Run', 'zpr647, Bike, Walk', 'gmp012, Jog, Bike' ] activity_list = clean_data(physical_activity_data) activites = unique_activities(activity_list) for a in activites: print(count_activites(a, activites), 'students', a, 'atleast once a week for more than 10 mins')

Question 1 14 points) 'run' 'run 'og vorkout' ualk' then the expected return value would be [ 'run , , , jog , " 'workout' , 'alk ' 'run''alk' Purpose: To practice using methods in the string object. Practice with mixing loops and conditionals, and basic List manipulation. Degree of Difficulty: Moderate. Data collection generally refers to the process of gathering and measuring data about specific things The measurements and results derived from data collection can be quite powerful and help researchers an- swer important quesitons Suppose we are helping a research lab at the U of S to analyze data they have collected about student's physical activity Students were given a survey and asked What physical activities do you do at least once a week for more than 10 minutes? Sadly, the records from the data collection came back in indvidual strings with comma separators. Ac- tivites also have inconsistent capitalization. So we will have to do some data cleaning before we analyze An examble of some of the data can be seen below The unique activites do not need to be returned in a specific order-any order is fine so long as all the unique words are included ld) Now to putall of our hard work together! In the main program (outside any function), call the function clean data) on the original lst provided (physical activity.datal to receive a new clean list. Now callthe unique activitea() function wih your new clean lst. Finally, use for-loopa to print out each activity and the rumber of times it occurs in the new clean list call the function count_activities for each activity. Sample Output aqc244, Run qqa640 run. Walk. Cv565, Jog. bike. zpr647,Bike Walk" jvu311, valk, Workout Your console output should look something like ths 12 students run at least once a veek for more than 10 minutea 14 students valk at least once a veek for sore than 10 sinute 11 gtudenta jog at least once a veek for more than 10 minutes We have provided you with a python file called a4q1 starter-py which defines a single list variable physical_activity data which includes all the collected data. Starting with this file, do the following 2 , tudent yorkout at leat once a week for more than 10 minute 1 atudents baseball at least once a vweek for sore than 10 sinutes 1 student lift at lea8t once a week ror more than 10 minutes a) Thedata isnt well formatted, solet's write a function tocleanitup. Write a functioncalled clean data) that takes one parameter, a list of activity records, and returns a list of strings (activities) For each item in the original list. you will have to do the following What to Hand In Use the string methodpit usage of oplitO to generate a list of the activites Here is an example showing the A file called a4q1.py containing your finished program, as described above. goat' define a atring variable new-list anisa18.8pl it (,') # 8P1 it with argument print (new liat) Evaluation ['dos', 'cat', 'pig,, ,goat,] # new-list now refers to this list . 4 marks for defining cleandata() that correctly uses aplit)atrip), and loercreating a list removing spaces.and changing activities to lower case. and returning a list of activities After spitting, use the string method lover and atrip to make sure all activities are lower .4 marks for defining countactivities that correctly return the number of occurrences of a given . 4 marks for defining unique_activitea) that correctly return the list of uniqueactivites in a given ist .2 marks for printing out the number of occurrences of each activity, one sentence per activity, and case and don't have leading or trailing spaces activty in a given list of activiles Add the clean activities to a new list that will be returned by yourclean data) function If you ran your clean data) function on the example data from earlier, it should return a list like this 'run'. run valk'jogbike.bike walk.valk. 'vorkout' of activites Note that this new list does not include the NSIDs from the previous list. We are not u our analysis so they can be ignored Be sure that you dion't add them to the return ist! using them for each sentence on ts own line. b) Write a function called count activites that takes two parameters: a string activity containing a single activity.and a list of stringsactivity.liat. The function must return the number of occurrences ofactivity inactivity liat. If we passed in the list from above. and the argument run. the function would return 2 (c) Write a function called unique activitieswth one parameter called activity list which is a list of strings where each string is a single activity The function should return a list of unique activities For example, if given the argument
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
