Question: Can someone write this function in Python. IMPORTANT: CALL THE help_recruit FUNCTION BELOW to convert each string to a tuple: def help_recruit(astr): firstlist = astr.split(:)

Can someone write this function in Python. IMPORTANT: CALL THE help_recruit FUNCTION BELOW to convert each string to a tuple:
def help_recruit(astr): firstlist = astr.split(":") name = firstlist[0].strip() secondlist = firstlist[1].split(",") sport = secondlist[0].strip() rank = int(secondlist[1]) return (sport,rank,name)
Test Cases:
>>> recruits= recruiting_profile(["Jair Anderson: Football,4","TaQuon Marshall: Football, 1", "Daniel Yun: Tennis, 3", "Gabby Benda: Volleyball, 7","Ashley Askin: Volleyball, 2", "Sydney Wilson: Volleyball, 5", "Chris Eubanks: Tennis, 1", "Zach Matthews: Football, 11", "Andrew Li: Tennis, 2"], "Tennis")
>>>print(recruits)
[(1, 'Tennis', 'Chris Eubanks'), (2, 'Tennis', 'Andrew Li'), (3, 'Tennis', 'Daniel Yun')]
>>> recruit1=recruiting_profile(["Wade Bailey: Baseball, 3", "Josh Okogie: Basketball, 1", "Tadric Jackson: Basketball, 4","Megan Young: Swimming, 7","Ben Lammers: Basketball, 2","Jake Lee: Baseball, 8","Brad Oberg: Swimming, 8","Megan Hansen: Swimming, 5","Joey Bart: Baseball, 5", "Matt Casillas: Swimming, 2"], "Swimming")
>>>print(recruit1)
[(2, 'Swimming', 'Matt Casillas'), (5, 'Swimming', 'Megan Hansen'), (7, 'Swimming', 'Megan Young'), (8, 'Swimming', 'Brad Oberg')]
>>> recruits2= recruiting_profile(["Lauren Frerking: Volleyball, 11","James Clark: Golf, 3", "Michael Pisciotta: Golf, 2" ], "Tennis")
>>> print(recruits2)
[]
Function name: recruiting profle Parameters: A list of strings, sport_name Return value: A list of tuples Description: Write a function that takes in a list of strings. The list can be empty, in which case return an empty list. Each string contains information about a person. You may assume that the string will always be formatted in this way: "NAME: SPORT, RANK". Call the help_recruit function to convert each string to a tuple. Find all the tuples that have sport_name and add them to a list sorted by their rank. However, the tuples in this list should be formatted as (RANK(int), SPORT (string), NAME(string)). No one will have the same rank. Return the list. Notes: If you have a function that returns a tuple of length three another way you can call the function and store the returned values is: a, b, c = myfunc () When sorting the tuples, you may use a built-in function. Test Cases: >>> recruits- recruiting-profile((" air Anderson: Football,4", "TaQuon Marshall: Football, 1", "Daniel Yun: Tennis, 3", "Gabby Benda: Volleyball, 7", "Ashley Askin: Volleyball, 2", "Sydney Wilson: Volleyball, 5", "Chris Eubanks: Tennis, 1", "Zach Matthews: Football, 11", "Andrew Li: Tennis, 2"] "Tennis") >>print(recruits)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
